JavaFX Anwendung exportieren

jimb0p

Erfahrenes Mitglied
Hallo Zusammen,

ich habe eine JavaFX Anwendung geschrieben welche auch fehlerfrei läuft in eclipse. Wenn ich Sie nun als Runnable Jar Exportiere und per java -jar name.jar ausführe bekomme ich folgende Fehlermeldung:

Code:
Exception in Application start method
java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(Unknown Source)
        at com.sun.javafx.application.LauncherImpl.launchApplication(Unknown Source)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
        at com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
        at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$147(Unknown Source)
        at com.sun.javafx.application.LauncherImpl$$Lambda$48/99550389.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalStateException: Location is not set.
        at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
        at javafx.fxml.FXMLLoader.load(Unknown Source)
        at de.ernst.main.MainApp.initRootLayout(MainApp.java:51)
        at de.ernst.main.MainApp.start(MainApp.java:35)
        at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$153(Unknown Source)
        at com.sun.javafx.application.LauncherImpl$$Lambda$51/43917691.run(Unknown Source)
        at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$166(Unknown Source)
        at com.sun.javafx.application.PlatformImpl$$Lambda$44/1268447657.run(Unknown Source)
        at com.sun.javafx.application.PlatformImpl.lambda$null$164(Unknown Source)
        at com.sun.javafx.application.PlatformImpl$$Lambda$47/867338085.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at com.sun.javafx.application.PlatformImpl.lambda$runLater$165(Unknown Source)
        at com.sun.javafx.application.PlatformImpl$$Lambda$45/1851691492.run(Unknown Source)
        at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
        at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
        at com.sun.glass.ui.win.WinApplication.lambda$null$141(Unknown Source)
        at com.sun.glass.ui.win.WinApplication$$Lambda$37/584634336.run(UnknownSource)

Die Zeilen die Dort erwähnt werden sind folgende:

Java:
public void initRootLayout() {
        try {
            // Load root layout from fxml file.
            FXMLLoader loader = new FXMLLoader();
            loader.setLocation(MainApp.class.getResource("../view/RootLayout.fxml"));
            rootLayout = (BorderPane) loader.load();

            // Show the scene containing the root layout.
            Scene scene = new Scene(rootLayout);
            primaryStage.setScene(scene);
            primaryStage.show();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

Was genau habe ich falsch gemacht?

Gruß!
 
Konnte es selbst herausfinden. Das Problem lag an Zeile fünf "../view/RootLayout.fxml" hier musste der komplette Pfad angegeben werden. Also "/de/blabla/view/RootLayout.fxml" wichtig ist hierbei der erste Slash!
 

Neue Beiträge

Zurück