我试图在我的javaFX项目中实现国际化。我的想法是从其他fxml文档中获取所有控制器,并在语言更改时调用每个控制器中的方法 @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
}
。获得控制器后我遇到了一些麻烦。这是我的NullPointerException
方法:
ac.loadLang("en");
我在AdsController.fxml
获得Thread mThread = new Thread() {
@Override
public void run() {
try {
for (int i = 0; i < temp; i++) {
runOnUiThread(new Runnable() {
@Override
public void run() {
// code to call your service
openTransaction();
}
});
sleep(60000); // one minute
}
} catch (InterruptedException e) {
e.printStackTrace();
}
super.run();
}
};
mThread.start();
。我很确定它是因为它没有正确获得mPlayerVC.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
的控制器。有什么想法吗?