3

I have a fxml file which has registered a Controller. The Controller implements EventHandler and so the method handle(ActionEvent e). If the registered event occur the code in the handler method is processed, but not always. But this following Exception trace is printed. Do I have missed something ?

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)
mr.wolle
  • 1,148
  • 2
  • 13
  • 21

1 Answers1

3

Ok, I solved the problem by myself:

I registered the handler function not only for "onAction" but also for the "onMouseReleased" event field. For that I have used SceneBuilder. But why actually can I not use "onMouseReleased" only "onAction" ?

mr.wolle
  • 1,148
  • 2
  • 13
  • 21
  • 1
    The onAction waits for EventHandler and onMouseReleased waits for a different type: EventHandler super MouseEvent>. That's why you are getting an "argument type mismatch" exception. I suppose SceneBuilder uses raw types or some reflection to generate the code, that's why the error is found only in runtime, not in compile time. – Petr Aug 27 '13 at 20:15