首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Java调试Eclipse中的错误?这些例外是什么意思?

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

Stack Overflow用户
提问于 2018-03-02 03:42:32
回答 1查看 43关注 0票数 0

我不知道如何调试它,我使用了两本不同的书和在线资源。我的代码甚至不能运行,我不明白为什么它不能作为一个有窗口的应用程序启动。错误下面的源代码。

堆栈跟踪:

代码语言:javascript
复制
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

我的代码:

代码语言:javascript
复制
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);
    }

}
EN

回答 1

Stack Overflow用户

发布于 2018-03-02 04:15:59

这是令人不快的一行:

代码语言:javascript
复制
primaryStage.setTitle("Hello World! Goodbye!"); //Make evil statement

因为你只需要:

代码语言:javascript
复制
Stage primaryStage = null;

中间没有实际的对象分配。

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49057499

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档