JavaFX 异常:内部图形尚未初始化
JavaFX Exception: Internal graphics not initialized yet
我试图在构造函数中加载一个控制器,为此我必须先调用 loader.load()
,否则 getController()
returns null
,因为我读过多个 Whosebug 答案。
protected static final FXMLLoader connectLoader = new FXMLLoader(GuiManager.class.getResource("/scenes/connect.fxml"));
private final ConnectController connectController;
public Gui() {
try {
connectLoader.load();
} catch (IOException e) {
e.printStackTrace();
}
connectController = connectLoader.getController();
}
但是 load() 抛出此异常:
javafx.fxml.LoadException:
/home/user/IdeaProjects/project/target/classes/scenes/connect.fxml:13
...
Caused by: java.lang.RuntimeException: Internal graphics not initialized yet
...
控制器在 fxml 的第一行指定:
<AnchorPane xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.project.gui.ConnectController">
fxml 文件的第 13 行(在异常中引用)是一个非常无害的
<Image url="@../image.png" />
非常欢迎任何建议,提前谢谢。
问题是Application的start()方法还没有执行完,调用load()时stage还没有创建。
关于如何测试这个的好建议也here
我试图在构造函数中加载一个控制器,为此我必须先调用 loader.load()
,否则 getController()
returns null
,因为我读过多个 Whosebug 答案。
protected static final FXMLLoader connectLoader = new FXMLLoader(GuiManager.class.getResource("/scenes/connect.fxml"));
private final ConnectController connectController;
public Gui() {
try {
connectLoader.load();
} catch (IOException e) {
e.printStackTrace();
}
connectController = connectLoader.getController();
}
但是 load() 抛出此异常:
javafx.fxml.LoadException:
/home/user/IdeaProjects/project/target/classes/scenes/connect.fxml:13
...
Caused by: java.lang.RuntimeException: Internal graphics not initialized yet
...
控制器在 fxml 的第一行指定:
<AnchorPane xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.project.gui.ConnectController">
fxml 文件的第 13 行(在异常中引用)是一个非常无害的
<Image url="@../image.png" />
非常欢迎任何建议,提前谢谢。
问题是Application的start()方法还没有执行完,调用load()时stage还没有创建。
关于如何测试这个的好建议也here