我不知道如何调试它,我使用了两本不同的书和在线资源。我的代码甚至不能运行,我不明白为什么它不能作为一个有窗口的应用程序启动。错误下面的源代码。
堆栈跟踪:
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);
}
}发布于 2018-03-02 04:15:59
这是令人不快的一行:
primaryStage.setTitle("Hello World! Goodbye!"); //Make evil statement因为你只需要:
Stage primaryStage = null;中间没有实际的对象分配。
我对javafx包以及Stage是如何创建的一无所知,但这似乎是一个很好的示例:https://examples.javacodegeeks.com/desktop-java/javafx/javafx-stage-example/
https://stackoverflow.com/questions/49057499
复制相似问题