使用Intellij运行javafx应用程序时出错

使用Intellij运行javafx应用程序时出错,java,intellij-idea,javafx,Java,Intellij Idea,Javafx,我有一个javafx程序,在迁移到intellij作为我的编辑环境之前,我以前是用sublime文本开发的。到目前为止,我可以通过命令行(Windows)编译和运行而不会出错。但是,当我尝试从intellij运行它时,我得到以下消息: Exception in Application start method Exception in thread "main" java.lang.RuntimeException: Exception in Application start method a

我有一个javafx程序,在迁移到intellij作为我的编辑环境之前,我以前是用sublime文本开发的。到目前为止,我可以通过命令行(Windows)编译和运行而不会出错。但是,当我尝试从intellij运行它时,我得到以下消息:

Exception in Application start method
Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:875)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$147(LauncherImpl.java:157)
at com.sun.javafx.application.LauncherImpl$$Lambda$1/868693306.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException: Location is required.
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3201)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3169)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3142)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3118)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3098)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3091)
at Main.setNewScene(Main.java:40)
at Main.start(Main.java:29)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$153(LauncherImpl.java:821)
at com.sun.javafx.application.LauncherImpl$$Lambda$50/2069914884.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$166(PlatformImpl.java:323)
at com.sun.javafx.application.PlatformImpl$$Lambda$46/646648017.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$164(PlatformImpl.java:292)
at com.sun.javafx.application.PlatformImpl$$Lambda$48/1106256089.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$165(PlatformImpl.java:291)
at com.sun.javafx.application.PlatformImpl$$Lambda$47/151108218.run(Unknown Source)
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$141(WinApplication.java:102)
at com.sun.glass.ui.win.WinApplication$$Lambda$38/2004449016.run(Unknown Source)
... 1 more

Process finished with exit code 1

我不知道如何修复此问题。

问题原来是intellij在项目目录中的源文件夹中有问题。通过将我的所有java文件移动到一个新目录,并在intellij中将其作为一个新项目使用一个正确的源文件夹重新打开,问题完全消失了


(如问题中所述,代码本身是功能性的,并通过命令行工作。)

您会收到此错误,因为FXMLoader无法加载fxml文件。最可能的情况是,您的IDE没有将FXML所在的目录识别为资源目录。添加有关项目结构以及如何通过cmd运行项目结构的详细信息可能有助于我们为您调试问题。@ItachiUchiha FXML文件与类文件位于同一目录中。也没有包声明,这意味着所有内容都在同一个目录中。您确定fxml文件与类文件在同一个目录中吗?还是仅仅是java文件?确保保存java和fxml文件的目录被标记为源目录。如果这不能解决问题,请添加用于加载fxml文件的代码以及项目的目录结构。@itachiUchiha所有内容、java文件、类文件、fxml文件和其他所有内容都在同一目录中。这是一个非常小的项目,所以为了简单起见,在当时将其全部放在一个文件夹中是有意义的。文件夹本身也被标记为源。请发布相关代码,否则将投票关闭此文件夹。