1

first of all, i'm definetly not a native speaker so I hope i can desribe correct what's about in this post :D

so what is the problem? When I try to construct an javaFX application with a a couple different "windows". The problem is when I try to biuld an initialize() function in my MainController class. This function should load first window with a login and password fields.

the problem shows only when I put some logic in initialize() method in my MainController class, to load another Window. For me that strange, because the main problem according to the console is that compiler cannot found a .fxml file which build the main window, not the second (which is build by the initialize() method.

If anybody know what seems to be the problem?

The error is:

Not found: .file:/C:/Users/ADMIN/workspace%20FX/SchoolList/target/classes/fxml/AppMainScreen.fxml //

that is an output from my try/catch block, the .fxml file is there for sure. the path and name is correct.

javafx.fxml.LoadException: /C:/Users/ADMIN/workspace%20FX/SchoolList/target/classes/fxml/AppMainScreen.fxml

at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441) at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409) at pl.mati.schoolList.app.SchoolListApp.start(SchoolListApp.java:28) 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(Thread.java:745)

Caused by: java.lang.NullPointerException at pl.mati.schoolList.controllers.MainController.initialize(MainController.java:73) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548) ... 12 more Exception in Application start method java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389) at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767) Caused by: java.lang.RuntimeException: Exception in Application start method at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917) at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182) at java.lang.Thread.run(Thread.java:745)

Caused by: java.lang.NullPointerException: Root cannot be null at javafx.scene.Scene.(Scene.java:336) at javafx.scene.Scene.(Scene.java:194) at pl.mati.schoolList.app.SchoolListApp.start(SchoolListApp.java:42) 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) ... 1 more Exception running application pl.mati.schoolList.app.SchoolListApp

Compiler cannot load fxml file, which leads to nullPointerException in places, where there should be StackPane injected (stackPane loaded from fxml File).

This is my classes: my main class, where the application is launched.

SchoolListApp.class

public class SchoolListApp extends Application{

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

    @Override
    public void start(Stage stage) throws Exception {
        FXMLLoader loader = new FXMLLoader();
        StackPane mainStackPane = null;

        URL path = getClass().getResource("/fxml/AppMainScreen.fxml");

        try {
            loader.setLocation(path);
            mainStackPane = (StackPane) loader.load();
        }
         catch (IOException e) {
            System.out.println("Not found: " + path);
            e.printStackTrace();

        }
        catch (Exception e) {

            // Answer:
            e.getCause().printStackTrace();

        }
        MainController controller = loader.getController();
        Scene scene = new Scene(mainStackPane);  //here i got the Caused by: java.lang.NullPointerException: Root cannot be null. error//

        stage.setScene(scene);

        stage.setTitle("School List Manager Application");
        stage.show();

    }

}

the main controller class. if the initiliazie method is empty - compiler works fine and it build the first window. but when I try to build another windows i got the error.

MainController.class

public class MainController implements Initializable{

    @FXML
    private StackPane mainStackPane;

    @FXML
    public void initialize(){

        FXMLLoader loader = new FXMLLoader();
        Pane pane = null;

        URL path;
        path = getClass().getResource("/fxml/HelloWindow.fxml");
        try {
            loader.setLocation(path);
            pane = loader.load();
        }
         catch (IOException e) {
            System.out.println("Not found: " + path);
            e.printStackTrace();

        }
        catch (Exception e) {

            // Answer:
            e.getCause().printStackTrace();

        }
        mainStackPane.getChildren().add(pane);

    }

    public MainController() {

    }
MDaniluk
  • 62
  • 2
  • 2
  • 16
  • It looks like your `HelloWindow.fxml` file has not been deployed to the build folder. Check what's in the `target/classes/fxml` folder inside the project folder (you can see the full path it is looking for in the error message) and see if both FXML files are there. – James_D Aug 21 '17 at 12:29
  • James, I checked and every fxml file created is in that directory. unfortunately, that's not the problem. thanks for trying to help me. – MDaniluk Aug 21 '17 at 20:36

0 Answers0