我正在尝试导出我最近创建的应用程序。它在Eclipse中完美运行,没有任何错误,但一旦导出它就无法启动,每当我尝试通过CMD运行它时,它会显示这些错误行
Exception in Application start method
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 org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoa
der.java:58)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown So
urce)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(
Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalStateException: Location is not set.
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.load(Unknown Source)
at vp.dict.main.MainApp.initLayouts(MainApp.java:61)
at vp.dict.main.MainApp.start(MainApp.java:53)
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 Sourc
e)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(Unknown S
ource)
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
我的代码块
public void start(Stage window) throws IOException {
this.window = window;
this.window.setTitle("EN/CZ Dictionary 2017");
**line 53 initLayouts();
}
public void initLayouts() throws IOException{
window.getIcons().add(new Image("/images/icon.png"));
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("../view/rootLayout.fxml"));
**line 61 BorderPane rootLayout = (BorderPane)loader.load();
Scene scene = new Scene(rootLayout);
window.setScene(scene);
RootController controller = loader.getController();
controller.setMainApp(this);
window.show();
// Load ContentController
loader = new FXMLLoader();
loader.setLocation(getClass().getResource("../view/contentLayout.fxml"));
AnchorPane ap = (AnchorPane)loader.load();
rootLayout.setCenter(ap);
ContentController contentController= loader.getController();
contentController.setMainApp(this);
controller.setContentController(contentController);
// Try to load last opened person file.
File file = getDataFilePath();
if (file != null) {
loadDataFromFile(file);
}
}