0

I'm trying to implement internationalization in my javaFX project. My idea was to get all the controllers from the other fxml documents and call the method loadLang in each of them when the language is changed. I'm having some trouble though with getting the controllers. Here's my changelanguage method:

    @FXML
    private void handleChangeLanguage(ActionEvent event) {
    FXMLLoader myLoader;
    myLoader = new FXMLLoader(getClass().getResource("Ads.fxml"));
    AdsController ac = myLoader.<AdsController>getController();
    tabPane.getTabs();
    if (countryBox.getSelectionModel().getSelectedIndex() == 0) {
        loadLang("da");
        ac.loadLang("da");
    }
    if (countryBox.getSelectionModel().getSelectedIndex() == 1) {
        ac.loadLang("en");
        loadLang("en");
    }
        //translate them to selected language
}  

I'm getting a NullPointerException at ac.loadLang("en");. I'm pretty sure it's because it didn't obtain the controller of AdsController.fxml properly. Any ideas?

dds
  • 2,335
  • 1
  • 31
  • 45
Jesper
  • 2,644
  • 4
  • 30
  • 65

0 Answers0