0

I'm not able to link my .fxml file. Also I'm new to java and haven't figured out how to link stuff and so on. Of course I tried searching google for an answer but didn't get far.

this is my file

public class loadingWindowTest extends Application{

public static void main(String[] args){
    launch(args);
}

@Override
public void start(Stage loadingWindowStage) throws Exception {
    try{
       FXMLLoader loadLoadingWindow = new FXMLLoader();
       loadLoadingWindow.setLocation( getClass().getResource("de.skullbro.pong.windows.loadingWindow.loadingWindow.fxml"));  
       loadLoadingWindow.setController( "de.skullbro.pong.windows.loadingWindow.loadingWindowController");
       Parent root = loadLoadingWindow.load();

       Scene scene = new Scene(root,(getSystemInformation.screenWidth * 0.5), (getSystemInformation.screenHeight * 0.5));

       loadingWindowStage.setScene(scene);
       loadingWindowStage.show();           
    }
    catch(Exception e){
        if(debug.DebugInformation()){
            Alert alert = new Alert(AlertType.ERROR);
            alert.setTitle("Fehler");
            alert.setHeaderText("");
            alert.setContentText(e.toString());
            alert.show();               
        }
        else{
            Alert alert = new Alert(AlertType.ERROR);
            alert.setTitle("Upps...");
            alert.setHeaderText("Something went wrong.");
            alert.setContentText("Please try to restart your Game. If this doesn't fix it contact the Developers");
            alert.show();   
        }
    }

}}

My Error is: Loaction is not set

What am I doing wrong? I'm not sure about my loadingWindow.setlocation()


Nor does this Work:

loadLoadingWindow.setLocation(getClass().getResource("de/skullbro/pong/windows/loadingWindow/loadingWindow.fxml"));

and here's a image of my Tree

mytree in eclipse

And her's the Error nullpointerexception that I am getting:

java.lang.NullPointerException
at de.skullbro.pong.windows.loadingWindow.loadingWindowTest.start(loadingWindowTest.java:26)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Unknown Source)
DaNeubi
  • 93
  • 11
  • `getClass().getResource("/de/skullbro/pong/windows/loadingWindow/loadingWindow.fxml")` and make sure eclipse includes the fxml in the classpath/jar... – fabian Aug 17 '17 at 15:30

1 Answers1

1

getResource() expects a path, not a list of package :

So you may change to :

loadLoadingWindow.setLocation(getClass().getResource("loadingWindow.fxml"));

Linked to

azro
  • 53,056
  • 7
  • 34
  • 70
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/152228/discussion-between-azro-and-daneubi). – azro Aug 18 '17 at 08:42