所以我试图启动我的JavaFX应用程序并出现堆栈跟踪错误:
Exception in thread "main" 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 sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.NullPointerException
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(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplication(Unknown Source)
我想知道发生了什么。在堆栈跟踪的底部,它表示在启动(args)方法中有一个NullPointer。我尝试了一切,但我无法让它工作。这是我的代码:
public class Main extends Application{
public void main(String[] args){
launch(args);
}
//START
//GUI
@Override
public void start(Stage primarystage) throws Exception {
SplitPane fullpane = new SplitPane();
//DECK
ScrollPane deckscrollpane = new ScrollPane();
AnchorPane deck = new AnchorPane();
deck.setOnMouseClicked((e)->{
System.out.println(e.getSceneX());
System.out.println(e.getSceneY());
});
Rectangle rec = new Rectangle();
rec.setTranslateX(23);
rec.setTranslateY(20);
rec.setWidth(200);
rec.setHeight(300);
deck.getChildren().add(rec);
deckscrollpane.setContent(deck);
//MAP
StackPane map = new StackPane();
fullpane.getItems().addAll(deckscrollpane, map);
fullpane.setDividerPositions(0.4f, 0.6f);
Scene scn = new Scene(fullpane, 700, 700);
primarystage.setScene(scn);
primarystage.show();
}
}
我是JavaFX的新手,我希望有经验的人可以解释我应该如何解决这个问题。我的IDE(Eclipse)也没有在代码中显示任何错误。运行程序时,只会弹出错误。我安装了JavaFX插件(我认为它被称为类似e(fx)clipse或类似的东西)。一点帮助?