启动画面后没有加载FXML文件

时间:2018-02-16 10:39:30

标签: java fxml scenebuilder

我在应用程序中添加启动画面时遇到问题。下面的代码是在Start.java中的程序开头运行启动画面。

@Override
public void start(Stage stage) throws Exception {
    Parent root=FXMLLoader.load(getClass().getResource("WelcomeScreen.fxml"));
    Scene scene=new Scene(root);
    stage.initStyle(StageStyle.UNDECORATED);
    stage.setScene(scene);
    stage.show();

}

下面的代码位于Welcomescreen.java中,它将设置一个计时器并加载主fxml文件。

class Screen extends Thread{
    @Override
    public void run() {
        try {
            Thread.sleep(1000);
            Platform.runLater(new Runnable() {
                @Override
                public void run() {

                    try {
                        Parent root=FXMLLoader.load(getClass().getResource("MainPage.fxml"));
                        Scene scene=new Scene(root);
                        Stage stage=new Stage();
                        stage.setScene(scene);
                        stage.show();
                    }
                    catch(IOException ex) {
                        Logger.getLogger(WelcomeScreen.class.getName()).log(Level.SEVERE,null,ex);
                    }

                    rootPane.getScene().getWindow().hide();
                }
            });
        }catch(InterruptedException ex) {
            Logger.getLogger(WelcomeScreen.class.getName()).log(Level.SEVERE,null,ex);
        }
    }

}

}

运行后,返回下面的堆栈跟踪,我无法弄清楚它出错的地方。

Caused by: java.lang.ClassNotFoundException: com.gluonhq.charm.glisten.control.TextField
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
at javafx.fxml/javafx.fxml.FXMLLoader.loadTypeForPackage(Unknown Source)
at javafx.fxml/javafx.fxml.FXMLLoader.loadType(Unknown Source)
... 19 more

1 个答案:

答案 0 :(得分:0)

更改fxml文件中TextField的导入。

更改

com.gluonhq.charm.glisten.control.TextField 

javafx.scene.control.TextField
相关问题