Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problem with running the app outside NetBeans (loading fxml from jar)

935832May 17 2012 — edited May 18 2012
Hello.
this problem occurs only when NOT using NetBeans (becouse NB may use this normal file sctructure, without jars)
here is part of my main class, start method
        //load FXMLs
        FXMLLoader primaryLoader = new FXMLLoader();
        URL primaryLocation = getClass().getResource("PrimaryStage.fxml");
        primaryLoader.setLocation(primaryLocation);
        
        Parent root = (Parent) primaryLoader.load();
        Scene primaryScene = new Scene(root);
        
        FXMLLoader secondaryLoader = new FXMLLoader();
        
        URL secondaryLocation = getClass().getResource("SecondaryStage.fxml");

        secondaryLoader.setLocation(secondaryLocation);
        
        System.out.println("sec loader = " +secondaryLoader.toString()
                +"\n sec loc from loader = "+secondaryLoader.getLocation()
                +"\n sec loc url = " + secondaryLocation
                +"\n pri loc url = " + primaryLocation);
        Parent secondaryRoot = (Parent) secondaryLoader.load();
        
        Scene secondaryScene = new Scene(secondaryRoot);
and the thing is the 1st url (primaryLocation) is loaded properly, and the secondLocation aint.
those 2 files are both in the same jar, same folder (packege) as main class.

the outcome looks like this
sec loader = javafx.fxml.FXMLLoader@5bde2a20
 sec loc from loader = null
 sec loc url = null
 pri loc url = jar:file:/C:/test_workspace/NetBeans/MZlike/dist/MoreAdvStuff.jar!/moreadvstuff/PrimaryStage.fxml
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.javafx.main.Main.launchApp(Main.java:486)
        at com.javafx.main.Main.main(Main.java:638)
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.access$000(Unknown Source)
        at com.sun.javafx.application.LauncherImpl$1.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalStateException: Location is not set.
        at javafx.fxml.FXMLLoader.load(Unknown Source)
        at moreadvstuff.MoreAdvStuff.start(MoreAdvStuff.java:55)
        at com.sun.javafx.application.LauncherImpl$5.run(Unknown Source)
        at com.sun.javafx.application.PlatformImpl$4.run(Unknown Source)
        at com.sun.javafx.application.PlatformImpl$3.run(Unknown Source)
        at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
        at com.sun.glass.ui.win.WinApplication.access$100(Unknown Source)
        at com.sun.glass.ui.win.WinApplication$2$1.run(Unknown Source)
        ... 1 more
where 55 line is
Parent secondaryRoot = (Parent) secondaryLoader.load();
any ideas how to fix it? loading the file manually from the jar may be a way, but its a workaround, not a solution

Edited by: Radosław on 2012-05-17 07:55
This post has been answered by Daniel on May 17 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 15 2012
Added on May 17 2012
2 comments
1,621 views