Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/352.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
应用程序启动方法中的JavaFX Maven异常_Java_Maven_Intellij Idea_Javafx_Javafx 11 - Fatal编程技术网

应用程序启动方法中的JavaFX Maven异常

应用程序启动方法中的JavaFX Maven异常,java,maven,intellij-idea,javafx,javafx-11,Java,Maven,Intellij Idea,Javafx,Javafx 11,所以我已经被这个问题困扰了好几天了。我在stackoverflow和其他网站上找到并阅读了很多帖子,但没有一个解决方案适合我。我在maven项目中的JavaFX有问题。我使用Java15和JavaFX15.0.1。 以下是我在项目中拥有的文件: pom.xml文件: <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM

所以我已经被这个问题困扰了好几天了。我在stackoverflow和其他网站上找到并阅读了很多帖子,但没有一个解决方案适合我。我在maven项目中的JavaFX有问题。我使用Java15和JavaFX15.0.1。 以下是我在项目中拥有的文件: pom.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>Maven_javaFx</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>15</maven.compiler.source>
        <maven.compiler.target>15</maven.compiler.target>
    </properties>


    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>15.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-graphics </artifactId>
            <version>15.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>15.0.1</version>
        </dependency>
    </dependencies>


</project>
以下是view.fxml文件:

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>


<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="controllers.controller">
   <children>
      <Pane layoutX="200.0" layoutY="100.0" prefHeight="200.0" prefWidth="200.0">
         <children>
            <Button layoutX="74.0" layoutY="100.0" mnemonicParsing="false" text="Button" />
         </children>
      </Pane>
   </children>
</AnchorPane>

以下是我试图编译代码时弹出的消息:

C:\Users\rafal\.jdks\openjdk-15\bin\java.exe --add-modules javafx.base,javafx.graphics --add-reads javafx.base=ALL-UNNAMED --add-reads javafx.graphics=ALL-UNNAMED "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.2.3\lib\idea_rt.jar=64406:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.2.3\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\rafal\Desktop\studia\Różne\Maven_javaFx\target\classes;C:\Users\rafal\.m2\repository\org\openjfx\javafx-controls\15.0.1\javafx-controls-15.0.1.jar;C:\Users\rafal\.m2\repository\org\openjfx\javafx-controls\15.0.1\javafx-controls-15.0.1-win.jar;C:\Users\rafal\.m2\repository\org\openjfx\javafx-graphics\15.0.1\javafx-graphics-15.0.1.jar;C:\Users\rafal\.m2\repository\org\openjfx\javafx-graphics\15.0.1\javafx-graphics-15.0.1-win.jar;C:\Users\rafal\.m2\repository\org\openjfx\javafx-base\15.0.1\javafx-base-15.0.1.jar;C:\Users\rafal\.m2\repository\org\openjfx\javafx-base\15.0.1\javafx-base-15.0.1-win.jar;C:\Users\rafal\.m2\repository\org\openjfx\javafx-fxml\15.0.1\javafx-fxml-15.0.1.jar;C:\Users\rafal\.m2\repository\org\openjfx\javafx-fxml\15.0.1\javafx-fxml-15.0.1-win.jar -p C:\Users\rafal\.m2\repository\org\openjfx\javafx-base\15.0.1\javafx-base-15.0.1-win.jar;C:\Users\rafal\.m2\repository\org\openjfx\javafx-graphics\15.0.1\javafx-graphics-15.0.1-win.jar main.Main
Exception in Application start method
java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1071)
Caused by: java.lang.RuntimeException: Exception in Application start method
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
    at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: java.lang.IllegalAccessError: class com.sun.javafx.fxml.FXMLLoaderHelper (in unnamed module @0x5d7c5b47) cannot access class com.sun.javafx.util.Utils (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.util to unnamed module @0x5d7c5b47
    at com.sun.javafx.fxml.FXMLLoaderHelper.<clinit>(FXMLLoaderHelper.java:38)
    at javafx.fxml.FXMLLoader.<clinit>(FXMLLoader.java:2138)
    at main.Main.start(Main.java:13)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
    ... 1 more
Exception running application main.Main
C:\Users\rafal\.jdks\openjdk-15\bin\java.exe--添加模块javafx.base,javafx.graphics--添加读取javafx.base=ALL-UNNAMED--添加读取javafx.graphics=ALL-UNNAMED”-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.2.3\lib\IDEA\rt.jar=64406:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.2.3\bin“-Dfile.encoding=UTF-8-classpath C:\Users\rafal\Desktop\studia\Różne\Maven_javaFx\target\classes;C:\Users\rafal\.m2\repository\org\openjfx\javafx controls\15.0.1\javafx-controls-15.0.1.jar;C:\Users\rafal\.m2\repository\org\openjfx\javafx controls\15.0.1\javafx-controls-15.0.1-win.jar;C:\Users\rafal\.m2\repository\org\openjfx\javafx graphics\15.0.1\javafx-graphics-15.0.1.jar;C:\Users\rafal\.m2\repository\org\openjfx\javafx graphics\15.0.1\javafx-graphics-15.0.1-win.jar;C:\Users\rafal\.m2\repository\org\openjfx\javafx base\15.0.1\javafx-base-15.0.1.jar;C:\Users\rafal\.m2\repository\org\openjfx\javafx base\15.0.1\javafx-base-15.0.1-win.jar;C:\Users\rafal\.m2\repository\org\openjfx\javafx fxml\15.0.1\javafx-fxml-15.0.1.jar;C:\Users\rafal\.m2\repository\org\openjfx\javafx fxml\15.0.1\javafx-fxml-15.0.1-win.jar-p C:\Users\rafal\.m2\repository\org\openjfx\javafx base\15.0.1\javafx-base-15.0.1-win.jar;C:\Users\rafal\.m2\repository\org\openjfx\javafx graphics\15.0.1\javafx-graphics-15.0.1-win.jar main.main
应用程序启动方法中的异常
java.lang.reflect.InvocationTargetException
位于java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(本机方法)
位于java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
位于java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
位于java.base/java.lang.reflect.Method.invoke(Method.java:564)
位于javafx.graphics/com.sun.javafx.application.LaunchImpl.launchApplicationWithArgs(LaunchImpl.java:464)
位于javafx.graphics/com.sun.javafx.application.LaunchImpl.launchApplication(LaunchImpl.java:363)
位于java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(本机方法)
位于java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
位于java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
位于java.base/java.lang.reflect.Method.invoke(Method.java:564)
位于java.base/sun.launcher.launchelper$FXHelper.main(launchelper.java:1071)
原因:java.lang.RuntimeException:应用程序启动方法中的异常
位于javafx.graphics/com.sun.javafx.application.LaunchImpl.launchApplication1(LaunchImpl.java:900)
在javafx.graphics/com.sun.javafx.application.LaunchImpl.lambda$launchApplication$2(LaunchImpl.java:195)
位于java.base/java.lang.Thread.run(Thread.java:832)
原因:java.lang.IllegalAccessError:class com.sun.javafx.fxml.FXMLLoaderHelper(在未命名模块@0x5d7c5b47中)无法访问class com.sun.javafx.util.Utils(在模块javafx.graphics中),因为模块javafx.graphics不会将com.sun.javafx.util导出到未命名模块@0x5d7c5b47
在com.sun.javafx.fxml.FXMLLoaderHelper上。(FXMLLoaderHelper.java:38)
在javafx.fxml.fxmloader。(fxmloader.java:2138)
在main.main.start处(main.java:13)
在javafx.graphics/com.sun.javafx.application.launchempl.lambda$launchApplication1$9(launchempl.java:846)
在javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
在javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
位于java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
位于javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
位于javafx.graphics/com.sun.glass.ui.invokelateDispatcher$Future.run(invokelateDispatcher.java:96)
在javafx.graphics/com.sun.glass.ui.win.WinApplication.\u runLoop(本机方法)
位于javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
... 还有一个
运行应用程序main.main时发生异常
我看到的关于这个问题的大多数帖子都是通过改变getResource()方法中的目录来解决的。我请求你帮助解决这个问题,因为我不知道该怎么办。任何帮助都将不胜感激。
感谢您的事先帮助。

感谢@JoséPereda的帮助,我找到了问题的解决方案。问题在于缺少JavaFX Maven插件和VM参数。

请阅读本教程。因为您使用的是Maven,所以需要JavaFXMaven插件,如中所示;或者,您需要应用正确的VM参数(请参阅)。最后,对您的资源使用
getClass().getResource(“/main/view.fxml”)
(前提是它位于
src/main/resources/main/view.fxml
下)。非常感谢@JoséPereda。添加插件和更改路径解决了我的问题。再次感谢你,你是救命恩人。@trashgood谢谢你的提示。我马上就去做,太好了;我在下面的回答中引用了@JoséPereda的评论,但您可能需要进一步说明如何应用到您的示例中。
C:\Users\rafal\.jdks\openjdk-15\bin\java.exe --add-modules javafx.base,javafx.graphics --add-reads javafx.base=ALL-UNNAMED --add-reads javafx.graphics=ALL-UNNAMED "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.2.3\lib\idea_rt.jar=64406:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.2.3\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\rafal\Desktop\studia\Różne\Maven_javaFx\target\classes;C:\Users\rafal\.m2\repository\org\openjfx\javafx-controls\15.0.1\javafx-controls-15.0.1.jar;C:\Users\rafal\.m2\repository\org\openjfx\javafx-controls\15.0.1\javafx-controls-15.0.1-win.jar;C:\Users\rafal\.m2\repository\org\openjfx\javafx-graphics\15.0.1\javafx-graphics-15.0.1.jar;C:\Users\rafal\.m2\repository\org\openjfx\javafx-graphics\15.0.1\javafx-graphics-15.0.1-win.jar;C:\Users\rafal\.m2\repository\org\openjfx\javafx-base\15.0.1\javafx-base-15.0.1.jar;C:\Users\rafal\.m2\repository\org\openjfx\javafx-base\15.0.1\javafx-base-15.0.1-win.jar;C:\Users\rafal\.m2\repository\org\openjfx\javafx-fxml\15.0.1\javafx-fxml-15.0.1.jar;C:\Users\rafal\.m2\repository\org\openjfx\javafx-fxml\15.0.1\javafx-fxml-15.0.1-win.jar -p C:\Users\rafal\.m2\repository\org\openjfx\javafx-base\15.0.1\javafx-base-15.0.1-win.jar;C:\Users\rafal\.m2\repository\org\openjfx\javafx-graphics\15.0.1\javafx-graphics-15.0.1-win.jar main.Main
Exception in Application start method
java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1071)
Caused by: java.lang.RuntimeException: Exception in Application start method
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
    at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: java.lang.IllegalAccessError: class com.sun.javafx.fxml.FXMLLoaderHelper (in unnamed module @0x5d7c5b47) cannot access class com.sun.javafx.util.Utils (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.util to unnamed module @0x5d7c5b47
    at com.sun.javafx.fxml.FXMLLoaderHelper.<clinit>(FXMLLoaderHelper.java:38)
    at javafx.fxml.FXMLLoader.<clinit>(FXMLLoader.java:2138)
    at main.Main.start(Main.java:13)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
    ... 1 more
Exception running application main.Main