I converted my "normal" Javafx project into a maven project to generate a modular image. Now I get this error pressing a menu button to load a fxml file. Despite the error, the fxml is still loaded.
@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");
}
if I delete diagramOptions.setVisible(true);
the error did not appear
full stacktrace:
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)
Before converting it into maven everything works fine