#Beginner - loading new screen in javafxml

4 messages · Page 1 of 1 (latest)

jagged schooner
#
    void onActionCreateAnimal(ActionEvent event) throws IOException {

        stage = ((Stage)((Button)event.getSource()).getScene().getWindow());

        scene = load(getClass().getResource("Create-Animal-Menu.fxml"));
        System.out.println(scene);
        stage.setScene(new Scene(scene));
        stage.show();

    }```

This is causing an error:
```Caused by: java.lang.NullPointerException: Location is required.
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3361)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3324)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3292)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3264)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3240)
    at javafx.fxml/javafx.fxml.FXMLLoader.load(FXMLLoader.java:3233)
    at woods.classdemo.classdemo/controller.MainMenuController.onActionCreateAnimal(MainMenuController.java:29)```

I have spent some time on this, I know it has to do with the specified path for the Create-Animal-Menu.fxml as it's returning null. I have tried various different paths (Path from content root / Path from Source Root / even absolute root starting from C:\)

I am working within the CreateAnimalController, and I have added a screenshot from the intelliJ hierarchy. I think I am just getting tunnel vision on this whole thing, so I am reaching out to see what I am missing. New to programming in general.
magic frostBOT
#

This post has been reserved for your question.

Hey @jagged schooner! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

jagged schooner
#

Self-resolved with /woods/classdemo/classdemo/Create-Animal-Menu.fxml - of the many times I tried, I must have missed the leading / - figured it was something stupidly simple :/