2014-07-23 21 views
1

我開始瀏覽Neko的教程,我想創建自己的特質。我一直在按照here的描述關注neko的文檔,但是它不斷產生錯誤。在Neko中產生NoSuchMethodException的deftrait

更具體:

; 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))))) 

製作錯誤:

java.lang.NoSuchMethodException:找不到在主$ eval1159 $ fn__160.invoke參數主要$ fn__153)方法.SetOnTextChange (NO_SOURCE_FILE:4)

有沒有人遇到過類似的問題,或者知道我做錯了什麼? 在此先感謝您的任何建議。

回答

1

我忘了在文檔中提到,在定義一個特徵之後,你還應該爲它的類型註冊它。

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

感謝您指出,我現在要更新文檔。

+0

謝謝你的快速和完美的答案。那就是訣竅。 – Nathan