因此,当我通过intellij运行它时,我的应用程序运行并正常运行,但是当我导出应用程序时,它甚至不会启动。这是我得到的Stack Trace。
Exception in Application start method
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:498)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
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:498)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalStateException: Location is not set.
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2434)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)
at application.UIController.start(UIController.java:42)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
... 1 more
Exception running application application.UIController
Process finished with exit code 1
这是它抱怨的代码。
public void start(Stage stage) {
screen = stage;
try {
FXMLLoader loader = new FXMLLoader(UIController.class.getResource("/fxml/LoginFXML.fxml"));
Parent root = loader.load();
loginController = loader.getController();
Scene scene = new Scene(root, 340, 487);
scene.getStylesheets().add(getClass().getResource("/css/application.css").toExternalForm());
screen.setScene(scene);
screen.show();
screen.setResizable(false);
screen.setTitle("Room Booking System");
if (launched.equals(false)) {
launched = true;
Database_Control launchdb = new Database_Control();
launchdb.launch();
}
Rectangle2D screenBounds = Screen.getPrimary().getVisualBounds();
screen.setX((screenBounds.getWidth() - screen.getWidth()) / 2);
screen.setY((screenBounds.getHeight() - screen.getHeight()) / 2);
} catch (IOException e) {
e.printStackTrace();
}
}
它抱怨没有设置位置,所以我尝试了
FXMLLoader loader = new FXMLLoader(); loader.setLocation(UIController.class.getResource("/fxml/LoginFXML.fxml"));
然而它一直给我同样的问题。提前谢谢。
答案 0 :(得分:0)
Location not set
错误意味着编译器找不到您所指的FXML文件。我确实看到您的FXML文件是loginFXML.fxml
,但您尝试使用大写L:LoginFXML.fxml
加载文件。这似乎对测试没有任何影响,但是在导出时可能会发生什么?