【问题标题】:JavaFX executable JAR runs into problems with loading FXML file, why isn't the FXML being loaded?JavaFX 可执行 JAR 在加载 FXML 文件时遇到问题,为什么没有加载 FXML?
【发布时间】:2015-08-31 11:45:16
【问题描述】:

下面是异常输出。我认为程序无法检索 FXML 文件“home.FXML”;它在这一行失败了:

Parent root = FXMLLoader.load(getClass().getResource("/fxml/home.fxml"));

这是加载 FXML 的类的其余部分。

public class Boorus extends Application{

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

public void start(Stage primaryStage) throws Exception{

    SQLboss.makeTables();
    Parent root = FXMLLoader.load(getClass().getResource("/fxml/home.fxml"));
    Scene scene = new Scene(root);

    primaryStage.setScene(scene);
    primaryStage.setTitle("Boorus");
    primaryStage.show();


}
}

我的项目结构如图所示:

在此处粘贴异常:http://pastebin.com/rWkRuury

【问题讨论】:

    标签: exception jar javafx executable


    【解决方案1】:

    正在加载 fxml 文件。问题是它坏了。

    里面有些东西在罐子里不起作用。除非您向我们展示 fxml,否则没有人可以帮助您。顺便说一句,这将是找不到文件时的异常:

    java.lang.NullPointerException: Location is required.
            at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
            at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
            at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
            at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
            at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
            at javafx.fxml.FXMLLoader.load(Unknown Source)
            at application.Main.start(Main.java:14)
            at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$159(Unknown Source)
            at com.sun.javafx.application.LauncherImpl$$Lambda$53/1018544248.run(Unknown Source)
            at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$172(Unknown Source)
            at com.sun.javafx.application.PlatformImpl$$Lambda$45/1586270964.run(Unknown Source)
    

    然而你的是:

    Caused by: javafx.fxml.LoadException:
    fxml/home.fxml
    
            at javafx.fxml.FXMLLoader.constructLoadException(Unknown Source)
            at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
            at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    

    它可以是各种各样的东西,比如 e。 G。 this one.

    【讨论】:

      【解决方案2】:

      .fxml 文件很可能未包含在您的JAR 文件中。

      在构建JAR 文件的步骤中,检查.fxml 文件是否包含在内而不是排除在外。

      如果您想查看 JAR 文件的内容但不知道如何:将扩展名重命名为 .zip(它实际上是一个 zip 文件)并打开它。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-01-07
        • 1970-01-01
        • 2016-04-14
        • 1970-01-01
        • 2018-10-23
        • 1970-01-01
        • 2014-02-03
        相关资源
        最近更新 更多