不能调用";javafx.scene.control.MenuButton.getScene()

不能调用";javafx.scene.control.MenuButton.getScene(),java,maven,javafx,Java,Maven,Javafx,我将我的“普通”Javafx项目转换为maven项目,以生成模块化图像。 现在,按下菜单按钮加载fxml文件时出现此错误。尽管有错误,fxml仍然被加载 @FXML private AnchorPane content = new AnchorPane(); @FXML private Menu diagramOptions; @FXML void openSimpleMode(ActionEvent event) throws InvalidFileFormatException, IOExc

我将我的“普通”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)错误没有出现

完整堆栈跟踪:

线程“JavaFX应用程序线程”java.lang.NullPointerException中的异常:无法调用“JavaFX.scene.control.MenuButton.getScene()”,因为“JavaFX.scene.control.skin.MenuButtonSkinBase.getSkinnable()”的返回值为null 位于javafx.controls/javafx.scene.control.skin.MenuButtonSkinBase.lambda$new$7(MenuButtonSkinBase.java:188) 在javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428) 位于java.base/java.security.AccessController.doPrivileged(AccessController.java:391) 位于javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427) 位于javafx.graphics/com.sun.glass.ui.invokelateDispatcher$Future.run(invokelateDispatcher.java:96) 在javafx.graphics/com.sun.glass.ui.win.WinApplication.\u runLoop(本机方法) 位于javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174) 位于java.base/java.lang.Thread.run(Thread.java:832)

在将其转换为maven之前,一切正常

问题在于javafx中存在一个bug。我切换到版本15,一切正常

Hmm。堆栈跟踪没有显示任何代码,只有JavaFX代码。你能提供一份工作吗?