我尝试移动我的fxml文件,但我似乎无法找到正确的文件路径。我的控制器也必须与我的fmxl文件在同一个包中。我在线阅读我应该把我的fxml文件放到资源文件夹中,这就是我所做的,但它还没有用。如果我将它移动到资源文件夹,我的控制器在UI文件夹中?
public class Main extends Application{
public Main() {
}
private static ArgumentParser argumentParser;
private static Stage primaryStage;
private static ArgumentResponder argumentResponder;
private static UncaughtExceptionLogger uncaughtExceptionLogger;
private static Settings settings;
/**
* The main method, for starting the application.
*
* <p>See {@link Argument} for the supported arguments.</p>
*
* @param args arguments given when starting KouChat.
*/
public static void main(String[] args){
argumentParser = new ArgumentParser(args);
argumentResponder = new ArgumentResponder(argumentParser);
if (!argumentResponder.respond()) {
return;
}
new LogInitializer(argumentParser.hasArgument(Argument.DEBUG));
// Initialize as early as possible to catch all exceptions
uncaughtExceptionLogger = new UncaughtExceptionLogger();
settings = loadSettings(argumentParser);
launch(args);
}
private static Settings loadSettings(final ArgumentParser argumentParser) {
final Settings settings = new Settings();
final ArgumentSettingsLoader argumentSettingsLoader = new ArgumentSettingsLoader();
argumentSettingsLoader.loadSettings(argumentParser, settings);
final PropertyFileSettingsLoader propertyFileSettingsLoader = new PropertyFileSettingsLoader();
propertyFileSettingsLoader.loadSettings(settings);
return settings;
}
@Override
public void start(Stage primaryStageObj) throws Exception{
primaryStage = primaryStageObj;
System.out.println(getClass().getResource("Chat.fxml"));
FXMLLoader loader = new FXMLLoader(getClass().getResource("Chat.fxml"));
ChatController pls = new ChatController(argumentParser, settings, uncaughtExceptionLogger);
loader.setController(pls);
pls.setStage(primaryStage);
Parent root = loader.load();
primaryStage.setTitle("Flake");
primaryStage.setScene(new Scene(root, 959,583 ));
primaryStage.setResizable(false);
primaryStage.show();
primaryStage.setResizable(false);
primaryStage.setOnCloseRequest(e -> Platform.exit());
}
}
这是我帮助查看我出错的项目路径
运行我的代码时收到的错误消息。
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:71)
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