我碰到了一些非常奇怪的行为来几次每遗忘的伎俩时间。的JavaFX的控制器负载
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("view/window.fxml"));
Parent root = loader.load();
GuiController controller = loader.getController();
现在controller
不为空。
但是,我这样做后...
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("view/window.fxml"));
Parent root = loader.load(getClass().getResource("view/window.fxml"));
GuiController controller = loader.getController();
的controller
现在null
。
我明白loader
莫名其妙地失去位置上他的夹子?我非常感谢有人告诉我这是一种预期的行为,并解释了为什么。
请注意,是看了不少关于这个问题没有发现任何岗位后,发现该解决方案唯一的实验2h后,所以请不要用外观相似的问题联系我。
你大概的意思是'loader',不'fxmlLoader'在这两个调用'setLocation(...)'。 –