无法在JavaFX中打开新窗口

无法在JavaFX中打开新窗口,javafx,scenebuilder,Javafx,Scenebuilder,当我将方法“openPlanes”放在按钮“onAction”选项中时。 这显示出许多错误。 但是如果我移除“开放平面”,他的开放法线 @FXML private void openPlanes() { openStage("view/Cadastro.fxml"); } private void openStage(String fxml) { try { Stage currentStage = (Stage) PLA

当我将方法“openPlanes”放在按钮“onAction”选项中时。 这显示出许多错误。 但是如果我移除“开放平面”,他的开放法线

@FXML
    private void openPlanes() {
        openStage("view/Cadastro.fxml");
    }

private void openStage(String fxml) {
        try {
            Stage currentStage = (Stage) PLANE.getScene().getWindow();
            Parent root = FXMLLoader.load(getClass().getResource(fxml));
            Scene scene = new Scene(root);
            Stage stage = new Stage(StageStyle.TRANSPARENT);
            stage.setScene(scene);
            stage.show();
            currentStage.hide();

        } catch (IOException ex) {
            Logger.getLogger(mainController.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

原因:javafx.fxml.LoadException:未指定控制器。 文件:/C:/Users/diego/Documents/NetBeansProjects/Automekanik/DGDSoft/dist/run708547813/DGD%20Soft.jar/dgdsoft/view/maindgdgdgd.fxml:23

at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2597)
at javafx.fxml.FXMLLoader.access$100(FXMLLoader.java:103)
at javafx.fxml.FXMLLoader$Element.getControllerMethodHandle(FXMLLoader.java:557)
at javafx.fxml.FXMLLoader$Element.processEventHandlerAttributes(FXMLLoader.java:599)
at javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:770)
at javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2823)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2532)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
at dgdsoft.DGDSoft.start(DGDSoft.java:19)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
... 1 more
运行应用程序dgdsoft.dgdsoft时出现异常
Java结果:1

首先确保您尝试加载的fxml资源位于您期望的目录中。如果它位于适当的目录中,则打开fxml文件并搜索字符串fx:controller。 确保控制器在规定的包装内

如果在fxml文件中找不到字符串fx:controller,则需要按以下方式编程:

 private Scene getScene(String fxmlPath, ControllerClass controller) {
        FXMLLoader loader;
        Parent parent;
        Scene scene;
        try {
            //not FXMLLoader.load(getClass().getResource(fxmlPath)
            loader = new FXMLLoader(getClass().getResource(fxmlPath));
            loader.setController(controller);
            parent = loader.load();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
        scene = new Scene(parent);

        return scene;

    }

最后,提交fxml文件和代码。

有哪些错误?什么是openStage(…)?我在分析这个家伙的应用程序GitHub-YouTube-我做了一些相同的部分来了解更多,我试图修改一些。现在我试图调用第二个窗口,但我不理解此错误,并且此代码“未指定控制器”也不表示您没有在FXML文件中指定控制器类。您好,您可以将DGDSoft代码或至少是start方法发布给我们吗?@yab问题出在FXML文件中。