我的主要课程似乎无法找到我的fmxl文件,但我非常确定路径是正确的。我不明白发生了什么。
这是我的主要
public void start(Stage primaryStageObj) throws Exception{
primaryStage = primaryStageObj;
// System.out.println(getClass().getResource("/net/usikkert/kouchat/practice.fxml"));
FXMLLoader loader2 = new FXMLLoader(getClass().getResource("/net/usikkert/kouchat/practice.fxml"));
Parent root2 = loader2.load();
System.out.println("controller set");
LoginController loginController = loader2.getController();
loginController.setArgumentParser(argumentParser);
loginController.setSettings(settings);
loginController.setUncaughtExceptionLogger(uncaughtExceptionLogger);
primaryStage.setTitle("Flake");
primaryStage.setScene(new Scene(root2, 250,439 ));
primaryStage.getIcons().add(new Image(getClass().getResourceAsStream("Perfect Version.png")));
primaryStage.show();
primaryStage.setResizable(false);
primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent e) {
Platform.exit();
System.exit( 0);
}
});
primaryStage.setTitle("Flake");
我收到的错误是
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$154(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 net.usikkert.kouchat.Main.start(Main.java:74)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(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$147(WinApplication.java:177)
... 1 more
Exception running application net.usikkert.kouchat.Main
Main.java:74的错误是我的加载程序调用{{1}} 我不明白错误是由我的fxml文件无法找到引起的?
答案 0 :(得分:0)
更改:
FXMLLoader loader2 = new FXMLLoader(getClass().getResource("/net/usikkert/kouchat/practice.fxml"));
到
FXMLLoader loader2 = new FXMLLoader(getClass().getResource("practice.fxml"));