简体   繁体   English

似乎无法让我的 JavaFX 成功运行。 我正在使用我的 class 所需的 JRE 10.0.2

[英]Can't seem to get my JavaFX to run successfully. I'm using JRE 10.0.2 as required for my class

enter image description hereNo other indications tell me the code is wrong except for when I try to run my code I get these errors.在此处输入图像描述没有其他迹象告诉我代码错误,除了当我尝试运行我的代码时出现这些错误。

Exception in Application start method
java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.base/java.lang.reflect.Method.invoke(Unknown Source)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(Unknown Source)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(Unknown Source)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.base/java.lang.reflect.Method.invoke(Unknown Source)
    at java.base/sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(Unknown Source)
    at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalArgumentException: StackPane@4df22f20is already inside a scene-graph and cannot be set as root
    at javafx.graphics/javafx.scene.Scene$8.invalidated(Unknown Source)
    at javafx.base/javafx.beans.property.ObjectPropertyBase.markInvalid(Unknown Source)
    at javafx.base/javafx.beans.property.ObjectPropertyBase.set(Unknown Source)
    at javafx.graphics/javafx.scene.Scene.setRoot(Unknown Source)
    at javafx.graphics/javafx.scene.Scene.<init>(Unknown Source)
    at javafx.graphics/javafx.scene.Scene.<init>(Unknown Source)
    at application.Shapes.start(Shapes.java:64)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(Unknown Source)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$11(Unknown Source)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$9(Unknown Source)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(Unknown Source)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(Unknown Source)
    ... 1 more
Exception running application application.Shapes
    package application;

import javafx.application.Application;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.StackPane;
import javafx.scene.shape.Rectangle;
import javafx.geometry.Insets;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Line;
import javafx.stage.Stage;
import javafx.scene.Group;
import javafx.scene.Scene;

public class Shapes extends Application {

    @Override
    public void start(Stage primaryStage) {
        BorderPane root = new BorderPane();
        Scene scene = new Scene(root,400,400);
        scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
        primaryStage.setScene(scene);
        primaryStage.show();

        //create rectangle and set properties
        Rectangle rectangle = new Rectangle();
        rectangle.setX(50);
        rectangle.setY(50);

        rectangle.setWidth(100);
        rectangle.setHeight(100);

        rectangle.setStroke(Color.BLUE);
        rectangle.setStrokeWidth(3);
        rectangle.setFill(Color.BLUE);

        //create circle and set properties
        Circle circle = new Circle(50);
        circle.setStroke(Color.RED);

        circle.setStrokeWidth(3);
        circle.setFill(Color.RED);

        //create cross and set properties
        Line vertical = new Line(-50 / 1.5, -50 / 2.5, 50 / 1.5, -50 / 2.5);
        Line horizontal = new Line(0, -50, 0, 50);
        horizontal.setStroke(Color.GREEN);
        horizontal.setStrokeWidth(6);
        vertical.setStroke(Color.GREEN);
        vertical.setStrokeWidth(6);

        //create pane to hold cross
        StackPane cross = new StackPane(vertical, horizontal);

        //create grid and set its properties
        GridPane grid = new GridPane();
        grid.setPadding(new Insets(5, 5, 5, 5));

        //add shapes to grid
        grid.add(cross, 2, 2);
        grid.add(rectangle, 0, 0);
        grid.add(circle, 1, 1);
        grid.add(new Group(vertical, horizontal), 2, 2);

        //create scene and add pane
        Scene newScene = new Scene(grid);

        //set name
        primaryStage.setTitle("Shapes");

        //add the scene to the stage
        primaryStage.setScene(newScene);

        //display stage
        primaryStage.show();


    }

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

}

I got it.我知道了。 I removed //BorderPane root = new BorderPane();我删除了 //BorderPane root = new BorderPane(); Scene scene = new Scene(root,400,400);场景场景 = 新场景(root,400,400); scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm()); scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm()); primaryStage.setScene(scene); primaryStage.setScene(场景); primaryStage.show();//主舞台.show();//

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 似乎无法使用UrlClassLoader加载我的班级 - Can't seem to get my class to load using UrlClassLoader 似乎无法让我的可执行bin运行 - Can't seem to get my executable bin to run 我似乎无法让Java读取我的文本文档 - I can't seem to get Java to read my text document 我正在使用Servlet,但似乎无法弄清楚为什么我的下载文件Servlet可以在本地运行,但不能正常运行 - I'm using Servlets and can't seem to figure out why my download file servlet will work locally, but not otherwise 将Java DLL放在JAVA_HOME \\ jre6 \\ bin中却无法使用java.library.path时,为什么我的Java项目可以在Eclipse中成功调用DLL? - Why can my Java project call my DLLs successfully in Eclipse when I place them in JAVA_HOME\jre6\bin but failed in using java.library.path? 我似乎无法让RadioButton在JavaFX中工作 - I can't seem to get RadioButtons to work within JavaFX 似乎无法在Eclipse中运行JavaFX项目 - Can't seem to run JavaFX project in Eclipse 为什么我的单元测试一直显示 NullPointerException? 我正在使用@BeforeClass,但它似乎不起作用 - Why does my Unit Test keep saying NullPointerException? I'm using @BeforeClass and it doesn't seem to work 我正在使用 JavaFX 并且我的组合框不想从 sql 数据库中填充 - I'm using JavaFX and my combobox doesn't want to populate from an sql database 使用@Autowire 链接我的@Service 类和@Repository 类会导致错误。 似乎无法找到解决方案 - Using @Autowire to link my @Service class and @Repository class causes error. Can't seem to find solution
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM