So I'm new to JavaFx and programming in general, and I'm having a problem where I cannot get a fxml file Controller into my program. Here's the Code
@FXML
private void handleBtnAdicionarAction(ActionEvent event) throws IOException {
Stage adicionarStage = new Stage();
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/AdicionarWindow.fxml"));
Parent root = (Parent) loader.load();
Scene scene = new Scene(root);
adicionarStage.setScene(scene);
adicionarStage.centerOnScreen();
adicionarStage.show();
awUI = loader.getController();
System.out.println(awUI);
awUI.associarController(this);
}
After I do this the field awUI should contain the Controller of the file I'm loading but it comes out null... I've been doing other projects where I do this method and it's been working I don't know what may be Wrong here. Can someone Help me with this ?
If you are using IntelliJ mark your resources directory, by right clicking on the resource folder, selecting Mark Directory as -> Resources Root. Inside your resources folder there should be an fxml containing your AdicionarWindow.fxml file. If not using Intellij please check on how your IDE works with Resources folder.
For more information on intellij click here.