fxml LoadException only when using MouseEvent ! (Java + Scene Builder)

296 Views Asked by At

I have a problem, i have an event handler that should do some code, apart from the code, the event handler accepts a MouseEvent and the event that will invoke it is onMouseClicked event, Everytime i try to run the program i get an exception, if i remove the MouseEvent and leave it empty or put any other type of event like just Event or ActionEvent it works, but this is not logical plus i need the mouse event because i will then check which mouse button is clicked in my code. i reviewed other people having the same questions and i did all what was in the answers to them but didn't work.

Exception + Stacktrace:

    javafx.fxml.LoadException: Error resolving onMouseClicked='#maginfyRecord', either the event handler is not in the Namespace or there is an error in the script.
    file:/D:/Personal/Projects/Tools/Java/Organizer/dist/run1842687407/Organizer.jar!/organizer/View/DatabaseTables.fxml:195

    at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2597)
    at javafx.fxml.FXMLLoader.access$100(FXMLLoader.java:103)
    at javafx.fxml.FXMLLoader$Element.processEventHandlerAttributes(FXMLLoader.java:610)
    at javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:770)
    at javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2823)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2532)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
    at organizer.Controller.Main.switchWindow(Main.java:32)
    at organizer.Controller.SecurityController.openOrSave(SecurityController.java:124)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    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:498)
    at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
    at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1771)
    at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
    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:49)
    at javafx.event.Event.fireEvent(Event.java:198)
    at javafx.scene.Node.fireEvent(Node.java:8411)
    at javafx.scene.control.Button.fire(Button.java:185)
    at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
    at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
    at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
    at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
    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:198)
    at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
    at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
    at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
    at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:394)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$353(GlassViewEventHandler.java:432)
    at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:431)
    at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
    at com.sun.glass.ui.View.notifyMouse(View.java:937)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
    at java.lang.Thread.run(Thread.java:748)

The event handler is as follows:

    @FXML
        public void magnifyRecord(MouseEvent event) {
            if ((event.getButton()== event.BUTTON2)) {
                TextArea area = new TextArea();
                area.setText(selectedTable.getSelectionModel().getSelectedItem().toString());    
                JFXPopup popup = new JFXPopup();
                popup.setPopupContent(area);
                popup.show(selectedTable);
                popup.show(selectedTable, event.getX(), event.getY());
            }     
        }

and here is the fxml for this portion:

<Tab fx:id="toDoListTab" onSelectionChanged="#switchTab" text="To Do List">
               <content>
                  <StackPane prefHeight="150.0" prefWidth="200.0">
                     <children>
                        <TableView fx:id="toDoListTable" prefHeight="200.0" prefWidth="200.0" />
                     </children>
                  </StackPane>
               </content>
            </Tab>
            <Tab fx:id="notesTab" onSelectionChanged="#switchTab" text="Notes">
               <content>
                  <StackPane prefHeight="150.0" prefWidth="200.0">
                     <children>
                        <TableView fx:id="notesTable" prefHeight="200.0" prefWidth="200.0" />
                     </children>
                  </StackPane>
               </content>
            </Tab>
            <Tab fx:id="contactsTab" onSelectionChanged="#switchTab" text="Contacts">
               <content>
                  <StackPane prefHeight="150.0" prefWidth="200.0">
                     <children>
                        <TableView fx:id="contactsTable" onMouseClicked="#magnifyRecord" prefHeight="200.0" prefWidth="200.0" />
                     </children>
                  </StackPane>
               </content>
            </Tab>
            <Tab fx:id="locationsTab" onSelectionChanged="#switchTab" text="Locations">
               <content>
                  <StackPane prefHeight="150.0" prefWidth="200.0">
                     <children>
                        <TableView fx:id="locationsTable" prefHeight="200.0" prefWidth="200.0" />
                     </children>
                  </StackPane>
               </content>
            </Tab>
            <Tab fx:id="productsTab" onSelectionChanged="#switchTab" text="Products">
               <content>
                  <StackPane prefHeight="150.0" prefWidth="200.0">
                     <children>
                        <TableView fx:id="productsTable" prefHeight="200.0" prefWidth="200.0" />
                     </children>
                  </StackPane>
               </content>
            </Tab>

I tried commenting out the code completely, no change, it only works if i remove the MouseEvent or replace it with any other event

I am using Netbeans + JDK 8 + Scene Builder + jfoenix library

1

There are 1 best solutions below

0
On BEST ANSWER

Try checking your imports, you must've imported the wrong MouseEvent. You should import

javafx.scene.input.MouseEvent

for the event handler and not any other MouseEvents.