简体   繁体   English

Eclipse Oxygen中的Java FX运行时异常

[英]Java FX Runtime Exception in Eclipse Oxygen

I am trying to run a simple Java FX program but keep getting a runtime error. 我正在尝试运行一个简单的Java FX程序,但始终遇到运行时错误。 I am not sure what this exception is or what is causing this. 我不确定此异常是什么或导致此异常的原因。 Here is my code below: 这是我的代码如下:

import javafx.application.*;
import javafx.stage.*;
import javafx.scene.*;
import javafx.scene.layout.*;
import javafx.scene.control.*;

public class Main extends Application {

    Stage window;
    Scene scene1, scene2;

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

    @Override
    public void start(Stage primaryStage) {
        window = primaryStage;

        //Button 1
        Label label1 = new Label("Welcome to the first scene!");
        Button button1 = new Button("Go to scene 2");
        button1.setOnAction(e -> window.setScene(scene2));

        //Layout 1 - children laid out in vertical column
        VBox layout1 = new VBox(20);
        layout1.getChildren().addAll(label1, button1);
        scene1 = new Scene(layout1, 200, 200);


        //Button 2
        Button button2 = new Button("This sucks, go back to scene 1");
        button2.setOnAction(e -> window.setScene(scene1));

        //Layout 2
        StackPane layout2 = new StackPane();
        layout2.getChildren().add(button2);
        scene2 = new Scene(layout2, 600, 300);

        //Display scene 1 at first
        window.setScene(scene1);
        window.setTitle("Title Here");
        window.show();
    }

}

Here is the stack trace: 这是堆栈跟踪:

java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.Error: Unresolved compilation problem: 

at application.Main.main(Main.java:13)
... 11 more
Exception running application application.Main

Any information that relates to cause of this exception will help. 与导致此异常的原因有关的任何信息都将有所帮助。 Thanks. 谢谢。

Maybe it is not the mistake of the code, I can run your code successfully by Netbeans. 也许这不是代码的错误,我可以通过Netbeans成功运行您的代码。 You may check the project or eclipse instead of the code. 您可以检查项目或Eclipse而不是代码。 And I cannot fix the error without more error information. 如果没有更多错误信息,我将无法修复错误。

在此处输入图片说明

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM