javafx写主程序的时候提示Exception in Application start method
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 com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplication(Unknown Source)
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.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassCastException: javafx.scene.layout.AnchorPane cannot be cast to javafx.scene.layout.BorderPane
at address.MainApp.initRootLayout(MainApp.java:29)
at address.MainApp.start(MainApp.java:20)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(Unknown Source)
... 1 more
Exception running application address.MainApp
这个错误 我开始以为是路径错误,修改多次路径
http://www.yiibai.com/javafx/main-programe.html
这是书写的时候的教程 刚开始的时候
FXMLLoader loader=new FXMLLoader();
rootLayout=(BorderPane) loader.load(MainApp.class.getResource("view/test1.fxml"));
System.out.println(MainApp.class.getResource("view/test1.fxml"));
一直输出为空,这个让人非常郁闷,然后尝试着学习getResource
http://blog.csdn.net/cdkd123/article/details/8506867
这个是getresource的教程
我应该获得是bin下面的 ,执行的时候不会去找。java文件,最后会调用.class文件,
class 。getResource是获得class的父级目录,然后后面的参数跟的是要找的内容,最后返回一个url路径。
我的错误是t.InvocationTargetException AnchorPane cannot be cast to javafx.scene.layout.BorderPane
fxml中写的是anchorpanel,但是最后书写变成了boderpanel