fxml LoadException仅在使用MouseEvent时! (Java +场景构建器)

时间:2018-11-25 04:52:08

标签: java javafx fxml scenebuilder jfoenix

我有一个问题,我有一个事件处理程序应该执行一些代码,除了代码之外,该事件处理程序还接受一个MouseEvent,并且将调用它的事件是onMouseClicked事件,每次我尝试运行该程序时例外,如果我删除MouseEvent并将其留空或将任何其他类型的事件(如Event或ActionEvent)都起作用,但这是不合逻辑的,而且我需要鼠标事件,因为然后我将检查在我的鼠标中单击了哪个鼠标按钮码。我查看了其他有相同问题的人,我做了所有回答,但没有用。

异常+ 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)

事件处理程序如下:

    @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());
            }     
        }

这是此部分的fxml:

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

我尝试完全注释掉代码,没有变化,只有在删除MouseEvent或将其替换为任何其他事件后,它才起作用

我正在使用Netbeans + JDK 8 + Scene Builder + jfoenix库

1 个答案:

答案 0 :(得分:2)

尝试检查您的导入,您必须导入了错误的MouseEvent。您应该导入

javafx.scene.input.MouseEvent

用于事件处理程序,而不用于其他任何MouseEvent