java JavaFX通过Exe4J打包为EXE后无法运行
我用JavaFX构建的项目在编译器中运行良好,但当我将其打包为EXe可执行文件时,它出错了。 运行打包的EXE程序时提示的错误消息如下:
java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.IllegalStateException: Location is not set.
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2459)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2435)
at cn.ambit.app.App.start(App.java:40)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
... 1 more
发生错误的函数:
@Override
public void start(Stage initStage) throws Exception {
FXMLLoader initFXMLLoader = new FXMLLoader(App.class.getResource("/view/initializationStage.fxml"));
AnchorPane anchorPane = initFXMLLoader.load(); // line 40
Scene scene = new Scene(anchorPane);
JMetroThemeManager.setSceneStyle(scene);
initStage.setScene(scene);
initStage.setResizable(false);
initStage.titleProperty().bind(I18N.createStringBinding("title"));
initStage.show();
}
从错误提示来看,FXML文件似乎无法读取,但奇怪的是,我在其他项目中使用了相同的方法读取FXML文件,当打包到可执行文件中时,它工作正常,对此我感到困惑
# 1 楼答案
我不知道为什么,但后来我创建了另一个JavaFX控制器类,从旧的控制器类复制了方法,并删除了旧的控制器类,问题就解决了