JavaFX failed to run after being packaged as EXE through Exe4J

127 views Asked by At

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

There are 1 answers

0
Tison On BEST ANSWER

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.