androidclojuretraitsneko

deftrait producing NoSuchMethodException in Neko


I started going through tutorials for Neko and I wanted to create my own trait. I've been following the documentation on neko as described here but it keeps producing errors.

To be more specific:

; Clojure code

(ns main
  (:use [neko.activity :only [defactivity set-content-view!]]
        [neko.threading :only [on-ui]]
        [neko.ui :only [make-ui config]]
        [neko.ui.traits :only [deftrait]]))

(deftrait :on-text-change
  {:attributes [:on-text-change]}
  [^android.widget.TextView wdg, {:keys [on-text-change]}, opts]
  (.addTextChangedListener wdg (reify android.text.TextWatcher
                                 (afterTextChanged [this _])
                                 (beforeTextChanged [this _ _ _ _])
                                 (onTextChanged [this, s, start, before, count]
                                   (on-text-change (.toString s) start before count)))))

(declare ^android.widget.LinearLayout mylayout)

(def main-layout [:linear-layout {:orientation :vertical, :id-holder true}
                  [:edit-text {:hint "Event name" :id ::name :on-text-change (fn [text _ _ _])}]
                  [:edit-text {:hint "Event location" :id ::location}]])

(defactivity MainActivity
  :def a
  :on-create
  (fn [this bundle]
    (on-ui
     (set-content-view! a
      (make-ui main-layout)))))

Produced Error:

java.lang.NoSuchMethodException: Couldn't find method .SetOnTextChange for argument main$fn__153) at main$eval1159$fn__160.invoke(NO_SOURCE_FILE:4)

Did anybody experience similar problems or got an idea what I'm doing wrong? Thanks in advance for any suggestions.


Solution

  • I forgot to mention in the documentation that after defining a trait you should also register it for the widget type.

    (neko.ui.mapping/add-trait! :edit-text :on-text-change)
    

    Thanks for pointing that out, I'm going to update the docs now.