2015-06-15 102 views
0

下面是异常输出。我认为该程序无法检索FXML文件“home.FXML”;它在这条线上失败:JavaFX可执行文件JAR遇到加载FXML文件的问题,为什么不加载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(); 


} 
} 

我的项目结构看起来如右图所示:

enter image description here

Pastebinned异常这里:http://pastebin.com/rWkRuury

回答

2

正在加载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

0

这是可能的.fxml文件不包含在JAR文件。

在构建JAR文件的步骤中,检查是否包含.fxml文件,但未排除。

如果您想检查您的JAR文件的内容,并且不确定如何:将扩展名重命名为.zip(它实际上是一个zip文件)并将其打开。