1
我得到的InvocationTargetException当我尝试从控制器(JavaFX的)调用一个方法,将代码放在如下:的InvocationTargetException调用控制器方法时 - JavaFX的
public void start(Stage stage) throws Exception {
URL location = getClass().getResource("startScreen.fxml");
FXMLLoader loader = new FXMLLoader();
loader.setLocation(location);
loader.setBuilderFactory(new JavaFXBuilderFactory());
//Getting hte controller
StartScreenController s = (StartScreenController)loader.getController();
//Where error occurs
s.setParent(this);
Parent root = (Parent) loader.load(location.openStream());
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
它正常工作时,我删除了“ setParent“行。
这似乎已经为其他人(尽我所知,当试图自己解决这个问题)。
任何帮助,将不胜感激,谢谢。
我得到的错误(s.setParent是38行)
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.javafx.main.Main.launchApp(Main.java:642)
at com.javafx.main.Main.main(Main.java:805)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:403)
at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:47)
at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:115)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.NullPointerException
at johnsoft.dndcommunication.DndCommunication.start(DndCommunication.java:38)
at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:206)
at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:173)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:73)
... 1 more
Java Result: 1
您似乎试图调用内部控制主类的东西,看到这个链接http://stackoverflow.com/questions/14059954/calling-view-method-in-controller/14063918#14063918 – invariant 2013-02-09 22:22:34
有InvocationTargetException的根本原因?如果是,哪一个? – 2013-02-10 00:22:53
我会发布整个错误消息,尽管它在发生错误的注释中说。 – 2013-02-10 11:18:35