英文:
JavaFX failed to run after being packaged as EXE through Exe4J
问题
项目我使用JavaFX构建的,在编译器中运行良好,但当将其打包为EXE可执行文件时出现问题。
运行打包后的EXE程序时,出现以下错误消息:
java.lang.RuntimeException: Application start 方法中的异常
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: 位置未设置。
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(); // 第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文件,将其打包为EXE可执行文件时可以正常工作,这让我感到困惑。
英文:
The project I built with JavaFX worked fine in the compiler, but when I packaged it as an EXe executable, it went wrong.
The error message prompted when running the packaged EXE program is as follows:
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
Function where the error occurs:
@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();
}
From the error prompt, it seems that the FXML file failed to read, but strangely enough I have used the same method to read FXML files in other projects and it works fine when packaged into EXE executables, for which I am confused.
答案1
得分: 0
我不知道为什么,但后来我创建了另一个JavaFX控制器类,复制了旧控制器类中的方法,然后删除了旧控制器类,问题就解决了。
英文:
I don't know why, but I later created another JavaFX controller class, copied the methods from the old controller class and deleted the old controller class, and the problem was solved.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论