【发布时间】:2020-02-24 06:25:35
【问题描述】:
我尝试了几乎所有可用的解决方案,但似乎没有任何效果我需要在 2 个 Javafx 场景之间传递 string,但是当我单击导航到下一个场景时,什么也没有发生。到目前为止,这是我的代码:
String myVariable = "test";
FXMLLoader loader =new FXMLLoader(getClass().getResource("/fxml/Comments.fxml"));
Parent root = null;
CommentsController commentsController = new CommentsController();
commentsController = loader.getController();
commentsController.transferMessage(myVariable);
Stage stage = new Stage();
stage.setScene(new Scene(root));
stage.show();
PS:我在第二个场景中设置了transferMessage() 方法。
【问题讨论】:
-
应该有一个
NullPointerException发生。加载程序的controller属性以及root保持null,因为您从不调用load()或为root分配不同的值。