我正在尝试在构造函数中加载控制器,为此,我必须先调用loader.load()
,否则getcontroller()
返回null
,因为我已经阅读了很多stackoverflow答案。
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" />
任何建议都非常欢迎,谢谢。