Null exception when I try to access the controller that I passed using JavaFX

I have a root layout with short tabs. From my main application, I open the root layout. There I included several FXML with their own controllers. I am trying to transfer the main controller to one of the Tabes controllers.

The problem I ran into, everything works as expected, but I get a null exception when I try to click the action button from a new tab.

RootLayout FXML

 <fx:indlue fx:id="myNewTabAnchorPane" source="NewTabFXML.fxml"/> 

RootLayout Controller

 @FXML NewTabController newTabController; mainTabPane.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Tab>(){ @override public void change(ObservableValue<? extends Tab> observable, Tab oldValue, Tab newValue){ if(newValue == myTab){ newTabController.setMyRootController(this); } 

NewTabController

 public void setMyRootController(RootController rootController){ this.rootController = rootController; System.out.println(rootController.getID); // this prints fine } 

However, if I initiate this action, I get empty from the same controller

 @FXML public void createAction(ActionEvent event) throws IOException{ System.out.println(rootController.getID); // with this I get null value. } 

What am I missing?

0
javafx
source share
1 answer

Here is the problem:

  @FXML NewTabController newTabController; 

It should be myNewTabAnchorPaneController , which is not partly the bottom name of the class, but fx:id + Controller concatenation.

+1
source share

All Articles