Java 8 Eclipse 尚未设置 Root 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21299038/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Root hasn't been set Error with Java 8 Eclipse
提问by j will
Recently I installed Java 8 build 124 for my JavaFX application and I started getting these errors:
最近我为我的 JavaFX 应用程序安装了 Java 8 build 124,我开始收到这些错误:
javafx.fxml.LoadException: Root hasn't been set. Use method setRoot() before load.
/Users/jonathan/Projects/Dominion/target/classes/dominion/application/controller/main_overview_tab.fxml:13
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2613)
at javafx.fxml.FXMLLoader.access0(FXMLLoader.java:104)
at javafx.fxml.FXMLLoader$RootElement.constructValue(FXMLLoader.java:1320)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:740)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2723)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)
at dominion.application.controller.MainOverviewTab.initView(MainOverviewTab.java:64)
at dominion.application.controller.MainOverviewTab.initializeController(MainOverviewTab.java:55)
at dominion.application.controller.GameSetupController.<init>(GameSetupController.java:37)
at dominion.application.controller.DashboardController.<init>(DashboardController.java:40)
at dominion.application.controller.MainController.<init>(MainController.java:37)
at dominion.application.Dominion.start(Dominion.java:18)
at com.sun.javafx.application.LauncherImpl.run(LauncherImpl.java:837)
at com.sun.javafx.application.PlatformImpl.run(PlatformImpl.java:335)
at com.sun.javafx.application.PlatformImpl.run(PlatformImpl.java:301)
at com.sun.javafx.application.PlatformImpl.run(PlatformImpl.java:298)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.run(PlatformImpl.java:298)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
javafx.fxml.LoadException: Root hasn't been set. Use method setRoot() before load.
/Users/jonathan/Projects/Dominion/target/classes/dominion/application/controller/players_tab.fxml:13
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2613)
at javafx.fxml.FXMLLoader.access0(FXMLLoader.java:104)
at javafx.fxml.FXMLLoader$RootElement.constructValue(FXMLLoader.java:1320)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:740)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2723)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)
at dominion.application.controller.PlayersTab.initView(PlayersTab.java:46)
My application works just fine under Java 7 builds 40 and 51, but not under Java 8 build 124. Here are the first few lines of my main_overview_tab.fxml file:
我的应用程序在 Java 7 版本 40 和 51 下运行良好,但在 Java 8 版本 124 下不能正常工作。 以下是我的 main_overview_tab.fxml 文件的前几行:
<fx:root type="javafx.scene.layout.AnchorPane" id="AnchorPane" fx:id="content" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-1.0" minWidth="-1.0" prefHeight="600.0" prefWidth="1000.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2">
<children>
<VBox prefHeight="-1.0" prefWidth="-1.0" AnchorPane.bottomAnchor="10.0" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="10.0">
<children>
<HBox prefHeight="-1.0" prefWidth="-1.0" VBox.vgrow="ALWAYS">
<children>
<VBox id="playersVBox" prefHeight="-1.0" prefWidth="-1.0" spacing="40.0" HBox.hgrow="ALWAYS">
<children>
<Label text="Players">
<font>
<Font size="18.0" fx:id="x3" />
</font>
<VBox.margin>
<Insets />
</VBox.margin>
</Label>
This question is very similar, but didn't seem to help my situation: JavaFX SceneBuilder 2.0 doesn't open FXML for custom components with fx:root as main layout tag.
这个问题非常相似,但似乎对我的情况没有帮助:JavaFX SceneBuilder 2.0 不会为 fx:root 作为主布局标签的自定义组件打开 FXML。
EDIT: Code to load FXML
编辑:加载 FXML 的代码
public class MainOverviewTab extends Tab implements IObserver {
@FXML public AnchorPane content;
private SingleGameSettings gameSettings;
private List<ImageView> overviewImages;
public MainOverviewTab() {
}
public void initializeController(SingleGameSettings gameSettings) {
this.gameSettings = gameSettings;
this.gameSettings.registerObserver(this);
initView();
}
private void initView() {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("main_overview_tab.fxml"));
fxmlLoader.setRoot(content);
fxmlLoader.setController(this);
try {
fxmlLoader.load();
}
catch (Exception e) {
e.printStackTrace();
}
this.setText("Overview Game");
this.setContent(content);
}
...