"fxmlLoadException: root value already specified" 但我从未设置根值
"fxmlLoadException: root value already specified" but I never set a root value
我正在尝试在单击超链接时打开一个新的 window。出于某种原因,它曾经工作过一次,然后我再也无法让它工作了。每次我 运行 它都会得到一个 javafx.fxml.LoadException: Root value already specified.
错误。问题是我没有在任何地方设置根值。
我尝试了 loader.setRoot(null)
但没有任何作用。我从来没有在我的 fxml 或常规方法中设置根,所以我不确定它是从哪里得到的。
这是加载新文件的方法window
@FXML
private void initialize(){
messageSupports.setOnMouseClicked(e -> {
try {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("/MessagingSupportLayout.fxml"));
// Parent root = (Parent) loader.load();
Stage secondaryStage = new Stage();
loader.setController(new MessagingSupport(mainController));
mainController.getContentPane().getChildren().add(loader.load());
secondaryStage.setTitle("Support");
secondaryStage.setHeight(500);
secondaryStage.setWidth(350);
Scene scene = new Scene(loader.load());
secondaryStage.setScene(scene);
secondaryStage.show();
} catch (IOException ex) {
ex.printStackTrace();
}
});
}
}
这是 MessagingSupportLayout.fxml
的 fxml。
<BorderPane xmlns="http://javafx.com/javafx"
prefHeight="400.0" prefWidth="600.0">
</BorderPane>
预期的结果是一个新的window打开。我在启动方法中的主 class 中设置了第一个 window 的标题、高度和宽度。我没有在那里或在 fxml 中为此声明根。如果你需要看,我可以post。感谢您的帮助!
想通了。 mainController.getContentPane().getChildren().add(loader.load());
行设置根。删除该行可以解决问题。
我正在尝试在单击超链接时打开一个新的 window。出于某种原因,它曾经工作过一次,然后我再也无法让它工作了。每次我 运行 它都会得到一个 javafx.fxml.LoadException: Root value already specified.
错误。问题是我没有在任何地方设置根值。
我尝试了 loader.setRoot(null)
但没有任何作用。我从来没有在我的 fxml 或常规方法中设置根,所以我不确定它是从哪里得到的。
这是加载新文件的方法window
@FXML
private void initialize(){
messageSupports.setOnMouseClicked(e -> {
try {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("/MessagingSupportLayout.fxml"));
// Parent root = (Parent) loader.load();
Stage secondaryStage = new Stage();
loader.setController(new MessagingSupport(mainController));
mainController.getContentPane().getChildren().add(loader.load());
secondaryStage.setTitle("Support");
secondaryStage.setHeight(500);
secondaryStage.setWidth(350);
Scene scene = new Scene(loader.load());
secondaryStage.setScene(scene);
secondaryStage.show();
} catch (IOException ex) {
ex.printStackTrace();
}
});
}
}
这是 MessagingSupportLayout.fxml
的 fxml。
<BorderPane xmlns="http://javafx.com/javafx"
prefHeight="400.0" prefWidth="600.0">
</BorderPane>
预期的结果是一个新的window打开。我在启动方法中的主 class 中设置了第一个 window 的标题、高度和宽度。我没有在那里或在 fxml 中为此声明根。如果你需要看,我可以post。感谢您的帮助!
想通了。 mainController.getContentPane().getChildren().add(loader.load());
行设置根。删除该行可以解决问题。