I'm new to JavaFX. I've created a JavaFX program and it worked well until something(idk what) happened. For example My main function load start menu and it works well
public void start(Stage stage) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(Main.class.getResource("startMenu.fxml"));
Scene scene = new Scene(fxmlLoader.load(),956,573);
stage.setTitle("Taxes");
stage.setScene(scene);
stage.show();
}
But when I click button register I get this errors:
java.lang.NullPointerException: Location is required.
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException: Root cannot be null
And this is my changeScene function
public static void changeScene(ActionEvent event, String fxmlFile, String title,String name,String last_name){
Parent root = null;
if(name!=null&&last_name!=null){
try{
FXMLLoader loader = new FXMLLoader(DBUtils.class.getClass().getResource(fxmlFile));
root = loader.load();
LogInController logInController = loader.getController();
logInController.setUserInfo(name,last_name);
}catch(Exception e){
e.printStackTrace();
}
}else{
try{
root=FXMLLoader.load(DBUtils.class.getClass().getResource(fxmlFile));
}catch(Exception e){
e.printStackTrace();
}
}
Stage stage =(Stage) ((Node) event.getSource()).getScene().getWindow();
stage.setTitle("Taxes");
stage.setScene(new Scene(root, 956,573));
stage.show();
}
I've tried to move fxml files out of resources but nothing has changed. Method changeScene I've done by tutorial and it worked perfectly