无法将javafx.scene.Scene强制转换为javafx.scene.layout.Pane

大家好,我是javafx构建的新手,我正尝试投射Pane,但似乎无法正常工作,我也不知道为什么,希望您能为我提供帮助,如果可以的话,谢谢!

  package application;

import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.fxml.FXMLLoader;


public class Main extends Application {
    @Override
    public void start(Stage primaryStage) {
        try {
            Pane root = (Pane)FXMLLoader.load(getclass().getResource("Interface.fxml"));
            Scene scene = new Scene(root,400,400);
            scene.getStylesheets().add(getclass().getResource("application.css").toExternalForm());
            primaryStage.setScene(scene);
            primaryStage.show();
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        launch(args);
    }
}

我得到的错误是

WARNING: Loading FXML document with JavaFX API of version 11.0.1 by JavaFX runtime of version 8.0.231
java.lang.ClassCastException: javafx.scene.Scene cannot be cast to javafx.scene.layout.Pane
    at application.Main.start(Main.java:14)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$8(LauncherImpl.java:863)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$7(PlatformImpl.java:326)
    at com.sun.javafx.application.PlatformImpl.lambda$null$5(PlatformImpl.java:295)
    at java.security.accessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$6(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$4(WinApplication.java:186)
    at java.lang.Thread.run(Unknown Source)

我使用Scenebuilder来构建fxml文件

sdxfvxcvbxdjifnpgois 回答:无法将javafx.scene.Scene强制转换为javafx.scene.layout.Pane

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2353761.html

大家都在问