希望这只是一个愚蠢的错误,但我看不到它。
; OK
=> (filter (fn [x] (= "addItemListener" (.getName x))) (.getMethods javax.swing.JComboBox))
(#<Method public void javax.swing.JComboBox.addItemListener(java.awt.event.ItemListener)>)
; Error
=> (let [combobox (javax.swing.JComboBox. (java.util.Vector. ['a 'b 'c]))]
(.addItemListener combobox
(proxy [java.awt.event.ItemListener] []
(itemStateChanged [item-event] (println (str "selection changed to " (.getSelectedItem combobox)))))
combobox))
java.lang.IllegalArgumentException: No matching method found: addItemListener for class javax.swing.JComboBox (NO_SOURCE_FILE:0)
为什么不能找到addItemListener
方法?
答案 0 :(得分:3)
您是第二次将组合框传递给addItemListener方法,您可能希望从let表单中返回它。
这应该有效:
(let [combobox (javax.swing.JComboBox. (java.util.Vector. ['a 'b 'c]))]
(.addItemListener combobox
(proxy [java.awt.event.ItemListener] []
(itemStateChanged [item-event]
(println (str "selection changed to "
(.getSelectedItem combobox))))))
combobox)