I have a mainController does follow:
@FXML
protected void onPizzaButton(ActionEvent event) throws IOException {
...
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("PiazzaView.fxml"));
Parent root = (Parent) fxmlLoader.load();
PizzaController pizzaView = fxmlLoader.getController();
pizzaView.initialize();
pizzaView.setMainController(this);
Scene newScene = new Scene(root);
Stage newStage = new Stage();
newStage.setScene(newScene);
newStage.show();
}
And a second controller as follow:
private MainController mainController;
public void setMainController(MainController controller){
this.mainController = controller;
}
public void initialize(){
try
{
Pizza pizza = mainController.getPizza(); // I keep getting null for 'mainController'
if (pizza instanceof Deluxe){
PizzaImage.setImage(new Image("file:Deluxe"));
pizzaName.setText("Deluxe");
}
}
catch(NullPointerException e)
{
System.out.print("NullPointerException Caught");
}
}
Does anyone have an idea of what's going on? I think I set up my path in two of fxml files correctly, it makes no sense why I don't get anything for my maincontroller setter method.