javafx questions

Asked 2 years ago, Updated 2 years ago, 84 views

    public void changeScenes(ActionEvent event, String viewName, String title) throws IOException{
            FXMLLoader loader = new FXMLLoader();
            loader.setLocation(getClass().getResource(viewName));
            Parent parent = loader.load();

            Scene scene = new Scene(parent);


            Stage stage = (Stage)((Node)event.getSource()).getScene().getWindow();
            stage.setTitle(title);
            stage.setScene(scene);
            stage.show();
        }
public void saveBreadButtonPushed(ActionEvent event) {

            SceneChanger sc = new SceneChanger();
            sc.changeScenes(event, "bread.fxml", "List");

Running this saveBreadButtonPushed results in a nullpointerException error. A nullpointerException error occurred in the stage.setTitle(title) line. I'd appreciate it if you could help me.

javafx

2022-09-21 11:51

1 Answers

(Stage)((Node)event.getSource()).getScene().getWindow();

This means that the return value of that line is null.

It is not known from the code given in part.

You need to try tracing using a debugger.


2022-09-21 11:51

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.