运行 Java FXML 项目时的异常(应用程序启动方法中的异常)

Exception when running a Java FXML project (Exception in Application start method)

我对 FXML 及其语法完全陌生,因此我必须 this Oracle的教程就这个话题做了一些研究。

我已经按照指定的方式完成了图 4-2 上方的所有操作(除了我使用的是 Eclipse 而不是 NetBeans),但是一旦我 运行 项目,这就是我得到的在控制台上:

Exception in Application start method

舞台及其组件均未出现。

此外,这个 window 显示:

我在 Internet 上做了一些研究,但找不到有关此主题的信息。 Whosebug上有关于它的问题,但问题原因不尽相同

FXMLTableView.java(主要方法):

package application;

public class FXMLTableView extends Application{

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

@Override
public void start(Stage primaryStage) throws Exception {

    Pane root = (Pane) FXMLLoader.load(getClass().getResource("fxml_tableview.fxml"));

    primaryStage.setTitle("This is a title");
    primaryStage.setScene(new Scene(root, 400, 400));
    primaryStage.show();

    }
}

fxml_tableview.fxml:

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

<?import javafx.scene.layout.AnchorPane?>

<GridPane alignment="CENTER" hgap="10.0" vgap="10.0"
    xmlns:fx="http://javafx.com/fxml"
    fx:controller="fxmltableview.FXMLTableViewController">
    <padding>
        <Insets bottom="10.0" left="10.0" right="10.0" top="10.0"/>
    </padding>
    <Label style="-fx-font: NORMAL 20 Tahoma;" text="Address Book"                
        GridPane.columnIndex="0" GridPane.rowIndex="0">
    </Label>
    <TableView fx:id="tableView" GridPane.columnIndex="0" 
        GridPane.rowIndex="1">
    </TableView>
</GridPane>

我认为没有必要显示 FXMLTableViewController,因为我还不必使用它,因此它实际上是空的,但以防万一:

package application;

public class FXMLTableViewController {

}

提前致谢!

已解决

问题是因为我没有导入我在 FXML 文件上使用的每个 类 的库。

这是必须的:

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<GridPane alignment="CENTER" hgap="10.0" vgap="10.0"
   xmlns:fx="http://javafx.com/fxml"
   fx:controller="fxmltableview.FXMLTableViewController">
   <padding>
      <Insets bottom="10.0" left="10.0" right="10.0" top="10.0"/>
   </padding>
   <Label style="-fx-font: NORMAL 20 Tahoma;" text="Address Book"                
    GridPane.columnIndex="0" GridPane.rowIndex="0">
   </Label>
   <TableView fx:id="tableView" GridPane.columnIndex="0" 
       GridPane.rowIndex="1">
   </TableView>
</GridPane>

@n247s 感谢您的帮助。