I have a ViewController class and a TabController class. TabController extends ViewController.
In the ViewController I make the Tabs dynamically and I would like to change the name of the Tab at some point. I am always getting Null Pointer...
ViewController class
public class ViewController implements Initializable {
@FXML
private TabPane tabPane;
@FXML
private Button addNewTabButton;
private Integer count = 1;
private SingleSelectionModel<Tab> selectionModel;
@Override
public void initialize(URL location, ResourceBundle resources)
{
selectionModel = tabPane.getSelectionModel();
}
@FXML
public void createNewTab(){
Tab newTab = new Tab();
try {
String id = count.toString();
newTab.setText("New Tab");
newTab.setClosable(true);
newTab.setId(id);
newTab.setContent(FXMLLoader.load(getClass().getResource("Tab.fxml")));
count++;
} catch (IOException e){
System.out.println("Error");
}
tabPane.getTabs().add(newTab);
selectionModel.selectLast();
}
public void setTabText(String text){
selectionModel.getSelectedItem().setText(text);
}
}
TabController class
public class TabController extends ViewController implements Initializable {
@FXML
private Button setTextButton;
@FXML
private void fooBar(){
setTabText("fooBar");
}
@Override
public void initialize(URL url, ResourceBundle rb) {
}
}
I am always getting NullPointer on the line: setTabText("fooBar"); (TabControllerClass)
The problem is exist if I want to reach the setTabText() method from the TabController class. (There is no error when I am calling the setTabText() within the ViewController).
Thank you for your help!