无法调用"javafx.scene.control.MenuButton.getScene()



我转换了我的"正常的";Javafx项目变成了一个maven项目来生成一个模块化的图像。现在我得到这个错误按下菜单按钮加载一个fxml文件。尽管出现错误,但fxml仍处于加载状态。

@FXML
private AnchorPane content = new AnchorPane();
@FXML
private Menu diagramOptions;
@FXML
void openSimpleMode(ActionEvent event) throws InvalidFileFormatException, IOException {
diagramOptions.setVisible(true);
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/SimpleMode.fxml"));
Node simpleModePane = null;
try {
simpleModePane = loader.load();
} catch (Exception e) {
System.out.println("error in loading pane");
}
content.getChildren().clear();
content.getChildren().add(simpleModePane);
simplecontroller = loader.getController();
if (simplecontroller != null) {
simplecontroller.initData(ldfParser, methods, this);
} else {
System.out.println("null Pointer exception");
}
System.out.println("error after this");
}

如果我删除diagramOptions.setVisible(true);,错误不会出现

完整堆栈:

Exception in thread "JavaFX Application Thread" java.lang.NullPointerException: Cannot invoke "javafx.scene.control.MenuButton.getScene()" because the return value of "javafx.scene.control.skin.MenuButtonSkinBase.getSkinnable()" is null
at javafx.controls/javafx.scene.control.skin.MenuButtonSkinBase.lambda$new$7(MenuButtonSkinBase.java:188)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:832)

在将其转换为maven之前,一切都很好

问题是javafx中的一个错误。我切换到版本15,一切都很好

最新更新