3

我有一个已注册控制器的 fxml 文件。Controller 实现 EventHandler 和方法 handle(ActionEvent e)。如果注册的事件发生,则处理处理程序方法中的代码,但并非总是如此。但是会打印以下异常跟踪。我错过了什么吗?

Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException: argument type mismatch
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:491)
    at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:491)
    at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
    at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1502)
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
    at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
    at javafx.event.Event.fireEvent(Event.java:203)
    at javafx.scene.Scene$MouseHandler.process(Scene.java:3544)
    at javafx.scene.Scene$MouseHandler.process(Scene.java:3375)
    at javafx.scene.Scene$MouseHandler.access$1900(Scene.java:3326)
    at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1617)
    at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2394)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:312)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:237)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:354)
    at com.sun.glass.ui.View.handleMouseEvent(View.java:514)
    at com.sun.glass.ui.View.notifyMouse(View.java:877)
    at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
    at com.sun.glass.ui.gtk.GtkApplication.access$200(GtkApplication.java:47)
    at com.sun.glass.ui.gtk.GtkApplication$5$1.run(GtkApplication.java:137)
    at java.lang.Thread.run(Thread.java:724)
4

1 回答 1

3

好的,我自己解决了这个问题:

我不仅为“onAction”注册了处理函数,还为“onMouseReleased”事件字段注册了处理函数。为此,我使用了 SceneBuilder。但为什么实际上我不能只使用“onMouseReleased”“onAction”?

于 2013-08-27T14:47:19.457 回答