如何使用Java调试Eclipse中的错误?这些例外是什么意思?

时间:2018-03-01 19:42:32

标签: java eclipse debugging

我不知道如何调试这个,我已经使用了两本不同的书籍和在线资源。我的代码甚至没有运行,我也不知道它为什么不能作为窗口应用程序启动。来自错误的来源。

堆栈跟踪:

Exception in thread "main" java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.NullPointerException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
    at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
    ... 5 more

我的代码:

import javafx.stage.Window;
import javafx.scene.*;
import javafx.scene.paint.*;
import javafx.scene.shape.*;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.FlowPane;
import javafx.stage.Stage;

public abstract class window extends Application {

    public void main( String args[]) {
        Stage primaryStage = null;
        FlowPane pane = new FlowPane();
        pane.setPadding(new Insets(10));
        pane.setMaxHeight(1080);
        pane.setMaxWidth(1920);
        pane.setHgap(5);
        pane.setVgap(5);

        pane.getChildren().addAll(new Button("Initiate Virtual Reality"),
                new TextField(), new Label("Enter Response"), new Button("Send "
            + "Response") );
        Scene scene = new Scene(pane, 720, 1280);
        primaryStage.setTitle("Hello World! Goodbye!"); //Make evil statement
        primaryStage.setScene(scene); //Place scene in the stage
        primaryStage.show(); //Display the stage
        Application.launch(args);
    }

}

1 个答案:

答案 0 :(得分:0)

这是违规行:

primaryStage.setTitle("Hello World! Goodbye!"); //Make evil statement

因为你刚才:

Stage primaryStage = null;

在实际对象分配之间没有。

我对javafx包以及如何创建阶段一无所知,但这似乎是一个很好的例子:https://examples.javacodegeeks.com/desktop-java/javafx/javafx-stage-example/