【问题标题】:Load exception Error in FXML file preventing program from runningFXML 文件中的加载异常错误阻止程序运行
【发布时间】:2021-02-27 01:43:17
【问题描述】:

我正在开发一个应用程序,当我尝试运行它时,我不断收到以下错误:

   Exception in Application start method
java.lang.reflect.InvocationTargetException

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(Thread.java:748)
Caused by: javafx.fxml.LoadException: 
/Users/x/IdeaProjects/management%20system/out/production/management%20system/login.fxml:11

下面是应用启动方法:

    public void start (Stage stage) throws Exception{
    Parent root = (Parent) FXMLLoader.load(getClass().getResource("login.fxml"));

    Scene scene = new Scene(root);
    stage.setScene(scene);
    stage.setTitle("Employee management system");
    stage.show(); //showing the window
}

下面是fxml文件:

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

<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.PasswordField?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
   *line 11 <AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="Controller">
   <children>
      <Label layoutX="30.0" layoutY="14.0" text="Database status " />
      <TextField fx:id="username" layoutX="30.0" layoutY="125.0" />
      <Label layoutX="30.0" layoutY="99.0" text="Username" />
      <Label layoutX="30.0" layoutY="174.0" text="Password" />
      <PasswordField fx:id="password" layoutX="30.0" layoutY="200.0" />
      <ComboBox fx:id="combobox" layoutX="30.0" layoutY="268.0" prefWidth="150.0" promptText="Manager/Employee" />
      <Button fx:id="Login" layoutX="61.0" layoutY="338.0" mnemonicParsing="false" text="Login" />
      <Label fx:id="dbstatus" layoutX="186.0" layoutY="14.0" text="Label" />
   </children>
</AnchorPane>

我假设错误与我的 fxml 文件有关,但是在查看文件后,我找不到可能的原因,想知道错误的原因是什么?

【问题讨论】:

  • 已更新以指示代码中的第 11 行
  • Controller在包中吗?
  • 不,它不在包中
  • 您的问题中出现的包含start() 方法的类的名称是什么?
  • @Abra 类的名字是 Login

标签: java exception load driver fxml


【解决方案1】:

我想通了,我必须从锚窗格中删除 fx:controller

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-14
    相关资源
    最近更新 更多