此fxml错误代码在JavaFx中是什么意思

这是我不断得到的错误代码:

 Nov 26,2019 12:33:25 AM javafx.fxml.FXMLLoader$ValueElement processValue
    WARNING: Loading FXML document with JavaFX API of version 11.0.1 by JavaFX runtime of version 8.0.221
    Exception in Application start method
    java.lang.reflect.invocationTargetException
        at sun.reflect.NativeMethodaccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodaccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodaccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
        at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
        at sun.reflect.NativeMethodaccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodaccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodaccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
    Caused by: java.lang.RuntimeException: Exception in Application start method
        at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
        at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$1(LauncherImpl.java:182)
        at java.lang.Thread.run(Unknown Source)
    Caused by: javafx.fxml.LoadException: Error resolving onaction='#handlebuttonaction',either the event handler is not in the Namespace or there is an error in the script.
    /D:/eclipse%20Java/Workspace/EmployeeApp1/bin/application/Directory.fxml:83

        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.load(FXMLLoader.java:2409)
        at application.Main.showMainView(Main.java:27)
        at application.Main.start(Main.java:20)
        at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$8(LauncherImpl.java:863)
        at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$7(PlatformImpl.java:326)
        at com.sun.javafx.application.PlatformImpl.lambda$null$5(PlatformImpl.java:295)
        at java.security.accessController.doPrivileged(Native Method)
        at com.sun.javafx.application.PlatformImpl.lambda$runLater$6(PlatformImpl.java:294)
        at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
        at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
        at com.sun.glass.ui.win.WinApplication.lambda$null$3(WinApplication.java:177)
        ... 1 more
    Exception running application application.Main

我的教授告诉我,这可能是我的应用程序的命名,我仔细检查了一下,命名应该在应用程序文件下。这是我的程序的文件设置:

此fxml错误代码在JavaFx中是什么意思

这是我通过运行main.java文件尝试显示的代码:

此fxml错误代码在JavaFx中是什么意思

Main.java

package application;

import java.io.IOException;
import javafx.application.Application;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;



public class Main extends Application {
    @FXML private Stage primaryStage;
    @FXML private BorderPane borderPane;
    @Override
    public void start(Stage primaryStage) throws IOException{
            this.primaryStage = primaryStage;
            this.primaryStage.setTitle("Assignment 5: by ");
            showMainView();

    }

        private void showMainView() throws IOException{
            FXMLLoader loader = new FXMLLoader();
            loader.setLocation(Main.class.getResource("Directory.fxml"));
            borderPane = loader.load();
            Scene scene = new Scene(borderPane);
            primaryStage.setScene(scene);
            primaryStage.show();
        }


    public static void main(String[] args) {
        launch(args);
    }
}

Directory.fxml

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.TitledPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.text.Font?>

<TitledPane text="Assignment 5-Kevin Yuan" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.DirectoryController">
   <content>
      <BorderPane fx:id="borderPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="350.0" prefWidth="320.0">
        <opaqueInsets>
            <Insets />
        </opaqueInsets>
        <padding>
            <Insets bottom="5.0" left="5.0" right="5.0" />
        </padding>
        <center>
            <BorderPane BorderPane.alignment="CENTER">
               <right>
                    <GridPane BorderPane.alignment="CENTER">
                        <columnConstraints>
                            <ColumnConstraints hgrow="SOMETIMES" maxWidth="1.7976931348623157E308" minWidth="62.0" />
                            <ColumnConstraints hgrow="SOMETIMES" maxWidth="245.0" minWidth="10.0" prefWidth="245.0" />
                        </columnConstraints>
                        <rowConstraints>
                            <RowConstraints maxHeight="35.0" minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
                            <RowConstraints maxHeight="35.0" minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
                            <RowConstraints maxHeight="35.0" minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
                            <RowConstraints maxHeight="35.0" minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
                            <RowConstraints maxHeight="35.0" minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
                        <RowConstraints maxHeight="35.0" minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
                        </rowConstraints>
                        <children>
                        <Label alignment="CENTER_RIGHT" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" text="Name:" textAlignment="CENTER">
                           <font>
                              <Font name="System Bold" size="14.0" />
                           </font>
                        </Label>
                            <Label alignment="CENTER_RIGHT" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" text="Company:" textAlignment="CENTER" GridPane.rowIndex="1">
                                <font>
                                    <Font name="System Bold" size="14.0" />
                                </font>
                            </Label>
                            <Label alignment="CENTER_RIGHT" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="50.0" prefWidth="94.0" text="Extension:" textAlignment="RIGHT" GridPane.rowIndex="2">
                                <font>
                                    <Font name="System Bold" size="14.0" />
                                </font>
                            </Label>
                            <TextField fx:id="txtFldName" disable="true" promptText="First Last" GridPane.columnIndex="1">
                                <GridPane.margin>
                                    <Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
                                </GridPane.margin>
                            </TextField>
                        <TextField fx:id="txtFldCompany" disable="true" layoutX="89.0" layoutY="85.0" onKeypressed="#btnLoad" promptText="department name" GridPane.columnIndex="1" GridPane.rowIndex="1" />
                        <TextField fx:id="txtFldExt" disable="true" layoutX="94.0" layoutY="15.0" onKeypressed="#btnLoad" promptText="Ext. number" GridPane.columnIndex="1" GridPane.rowIndex="2" />
                            <HBox alignment="BOTTOM_RIGHT" GridPane.columnIndex="1" GridPane.rowIndex="3">
                                <children>
                                    <Label fx:id="lblCurrRecord" alignment="CENTER" contentDisplay="CENTER" maxHeight="25.0" maxWidth="1.7976931348623157E308" minHeight="25.0" prefHeight="25.0" prefWidth="150.0" text="? of ?" textAlignment="CENTER">
                                        <font>
                                            <Font name="System Bold Italic" size="12.0" />
                                        </font>
                                        <HBox.margin>
                                            <Insets bottom="5.0" />
                                        </HBox.margin>
                                    </Label>
                              <Button fx:id="btnNavDel" alignment="CENTER" contentDisplay="RIGHT" disable="true" maxWidth="35.0" minWidth="35.0" mnemonicParsing="false" onaction="#handlebuttonaction" onmouseclicked="#reactToClick" prefWidth="35.0" text="-">
                                 <font>
                                    <Font name="SansSerif Bold" size="12.0" />
                                 </font>
                                 <opaqueInsets>
                                    <Insets left="20.0" />
                                 </opaqueInsets>
                                 <HBox.margin>
                                    <Insets bottom="5.0" />
                                 </HBox.margin>
                              </Button>
                                    <Button fx:id="btnNavAdd" Visible="false" alignment="CENTER" disable="true" maxWidth="35.0" minWidth="35.0" mnemonicParsing="false" onaction="#handlebuttonaction" onmouseclicked="#reactToClick" prefWidth="35.0" text="+">
                                        <font>
                                            <Font name="SansSerif Bold" size="12.0" />
                                        </font>
                                        <HBox.margin>
                                            <Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
                                        </HBox.margin>
                                    </Button>
                                </children>
                            </HBox>
                            <HBox alignment="BOTTOM_RIGHT" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" GridPane.columnIndex="1" GridPane.rowIndex="4">
                                <children>
                              <Button fx:id="btnNavPrev" alignment="CENTER" disable="true" maxWidth="35.0" minWidth="35.0" mnemonicParsing="false" onaction="#handlebuttonaction" onmouseclicked="#reactToClick" prefWidth="35.0" text="&lt;&lt;">
                                 <font>
                                    <Font name="SansSerif Bold" size="12.0" />
                                 </font>
                                 <HBox.margin>
                                    <Insets bottom="5.0" />
                                 </HBox.margin>
                              </Button>
                                    <Button fx:id="btnNavNext" alignment="CENTER" disable="true" maxWidth="35.0" minWidth="35.0" mnemonicParsing="false" onaction="#handlebuttonaction" onmouseclicked="#reactToClick" prefWidth="35.0" text="&gt;&gt;">
                                        <font>
                                            <Font name="SansSerif Bold" size="12.0" />
                                        </font>
                                        <HBox.margin>
                                            <Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
                                        </HBox.margin>
                                    </Button>
                                </children>
                            </HBox>
                        </children>
                    </GridPane>
               </right>
            </BorderPane>
        </center>
         <bottom>
            <BorderPane BorderPane.alignment="CENTER">
                <right>
                    <HBox BorderPane.alignment="CENTER">
                        <children>
                            <Button fx:id="btnLoad" alignment="TOP_RIGHT" mnemonicParsing="false" onaction="#handlebuttonaction" onmouseclicked="#reactToClick" text="Load" textAlignment="RIGHT">
                                <HBox.margin>
                                    <Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
                                </HBox.margin>
                            </Button>
                            <Button fx:id="btnSerialize" alignment="CENTER" disable="true" mnemonicParsing="false" onaction="#handlebuttonaction" text="Serialize" textAlignment="RIGHT">
                                <HBox.margin>
                                    <Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
                                </HBox.margin>
                            </Button>
                        </children>
                    </HBox>
                </right>
                <center>
                    <Label fx:id="lblFilename" maxHeight="25.0" maxWidth="1.7976931348623157E308" text="File: not set" BorderPane.alignment="CENTER" />
                </center>
            </BorderPane>
         </bottom>
         <top>
            <Button fx:id="btnExit" alignment="CENTER" mnemonicParsing="false" onaction="#handlebuttonaction" onmouseclicked="#Save" onmouseReleased="#Exit" prefWidth="92.0" style="" text="Save and Exit" textAlignment="CENTER" BorderPane.alignment="TOP_RIGHT">
                <font>
                    <Font name="System Bold" size="12.0" />
                </font>
                <BorderPane.margin>
                    <Insets bottom="10.0" top="5.0" />
                </BorderPane.margin>
            </Button>
         </top>
      </BorderPane>
   </content>
</TitledPane>
li797979 回答:此fxml错误代码在JavaFx中是什么意思

Caused by: javafx.fxml.LoadException: Error resolving onAction='#handlebuttonAction',either the event handler is not in the Namespace or there is an error in the script.
    /D:/Eclipse%20Java/Workspace/EmployeeApp1/bin/application/Directory.fxml:83

阅读上面的错误消息:either the event handler is not in the Namespace or there is an error in the script.,表示您正在调用不存在的按钮按下方法。检查以下FXML代码行:

<Button fx:id="btnExit" alignment="CENTER" mnemonicParsing="false" onAction="#handlebuttonAction" onMouseClicked="#Save" onMouseReleased="#Exit" prefWidth="92.0" style="" text="Save and Exit" textAlignment="CENTER" BorderPane.alignment="TOP_RIGHT">

可能的解决方案: 您可以从FXML代码中删除此onAction="#handlebuttonAction"。 (我上面提到的那行。)

本文链接:https://www.f2er.com/3031609.html

大家都在问