gpt4 book ai didi

java - JavaFX调用目标异常-未设置非法状态异常目标

转载 作者:行者123 更新时间:2023-12-02 10:59:06 25 4
gpt4 key购买 nike

我的主类似乎找不到我的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处的错误是我的加载程序调用 Parent root2 = loader2.load();我不明白错误原因是由于找不到我的fxml文件?

那是我项目的路
This is the path of my project

最佳答案

更改:

 FXMLLoader loader2 = new FXMLLoader(getClass().getResource("/net/usikkert/kouchat/practice.fxml"));


FXMLLoader loader2 = new FXMLLoader(getClass().getResource("practice.fxml"));

关于java - JavaFX调用目标异常-未设置非法状态异常目标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49663099/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com