IntelliJ IDEA - 错误:缺少 JavaFX 运行时组件,需要运行此应用程序 [英] IntelliJ IDEA - Error: JavaFX runtime components are missing, and are required to run this application

查看:218
本文介绍了IntelliJ IDEA - 错误:缺少 JavaFX 运行时组件,需要运行此应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 JDK 11.0.1OpenJFX 的 JavaFX 11 运行 IntelliJ IDEA Ultimate 2018.2.5.我知道这是一个常见错误,我尝试了许多建议的修复程序,但没有任何效果.

无论我尝试运行哪个 JavaFX 项目,都会出现错误:

错误:缺少 JavaFX 运行时组件,需要运行此应用程序

如果我将以下内容添加到 VM 选项

 --module-path="C:Program FilesJavajavafx-sdk-11lib" --add-modules=javafx.controls

我收到这些错误:

应用程序启动方法中的异常java.lang.reflect.InvocationTargetException在 java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)在 java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)在 java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)在 java.base/java.lang.reflect.Method.invoke(Method.java:566)在 javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)在 javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)在 java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)在 java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)在 java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)在 java.base/java.lang.reflect.Method.invoke(Method.java:566)在 java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)引起:java.lang.RuntimeException:应用程序启动方法中的异常在 javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)在 javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)在 java.base/java.lang.Thread.run(Thread.java:834)引起:java.lang.IllegalAccessError: class com.sun.javafx.fxml.FXMLLoaderHelper (in unnamed module @0x5fce9dc5) cannot access class com.sun.javafx.util.Utils (in module javafx.graphics) 因为模块 javafx.graphics不会将 com.sun.javafx.util 导出到未命名的模块 @0x5fce9dc5在 com.sun.javafx.fxml.FXMLLoaderHelper.<clinit>(FXMLLoaderHelper.java:38)在 javafx.fxml.FXMLLoader.<clinit>(FXMLLoader.java:2056)在 sample.Main.start(Main.java:13)在 javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.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(Native Method)在 javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)在 javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)在 javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(本机方法)在 javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)... 1个运行应用程序示例的异常.Main

我尝试重新安装,但没有任何运气.我也尝试过改变getClass().getResource(...)getClass().getClassLoader().getResource(...) 或类似 Parent root = FXMLLoader 的东西.load(getClass().getResource("/sample.fxml")); 但还是不行.

解决方案

有类似的问题 this 或其他 一个.

在 JavaFX 11 之前,无论何时调用与 JavaFX 相关的内容,您都可以在 SDK 中使用所有 javafx 模块.

但是现在您必须包含您需要的模块/依赖项.

您的错误表明您正在使用 FXML 但无法解决,但您刚刚添加了 javafx.controls 模块:

--add-modules=javafx.controls

正如您在 JavaDoc 中所见,javafx.controls 模块依赖于 javafx.graphicsjava.base,但这些模块都不包含 FXML 类.

如果你需要像 FXMLLoader 这样的 FXML 类,你需要包含 javafx.fxml 模块:

 --module-path="C:Program FilesJavajavafx-sdk-11lib" --add-modules=javafx.controls,javafx.fxml

如果您需要媒体或 webkit,同样适用,它们有自己的模块.>

I'm running IntelliJ IDEA Ultimate 2018.2.5 with JDK 11.0.1 and JavaFX 11 from OpenJFX. I know it's a common error and I tried many of the proposed fixes but nothing works.

No matter which JavaFX project I try to run I get the error:

Error: JavaFX runtime components are missing, and are required to run this application

If I add the following to the VM options

 --module-path="C:Program FilesJavajavafx-sdk-11lib" --add-modules=javafx.controls

I get these errors:

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:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    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:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
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:834)
Caused by: java.lang.IllegalAccessError: class com.sun.javafx.fxml.FXMLLoaderHelper (in unnamed module @0x5fce9dc5) 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 @0x5fce9dc5
    at com.sun.javafx.fxml.FXMLLoaderHelper.<clinit>(FXMLLoaderHelper.java:38)
    at javafx.fxml.FXMLLoader.<clinit>(FXMLLoader.java:2056)
    at sample.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(Native Method)
    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 sample.Main

I tried reinstalling without any luck. I have also tried to change getClass().getResource(...) to getClass().getClassLoader().getResource(...) or to something like Parent root = FXMLLoader.load(getClass().getResource("/sample.fxml")); but still doesn't work.

解决方案

There are similar questions like this or this other one.

Before JavaFX 11, whenever you were calling something JavaFX related, you had all the javafx modules available within the SDK.

But now you have to include the modules/dependencies you need.

Your error says that you are using FXML but it can't be resolved, but you have just added the javafx.controls module:

--add-modules=javafx.controls

As you can see in the JavaDoc the javafx.controls module depends on javafx.graphics and java.base, but none of those modules includes the FXML classes.

If you need FXML classes like the FXMLLoader, you need to include javafx.fxml module:

 --module-path="C:Program FilesJavajavafx-sdk-11lib" 
    --add-modules=javafx.controls,javafx.fxml

The same will apply if you need media or webkit, those have their own modules.

这篇关于IntelliJ IDEA - 错误:缺少 JavaFX 运行时组件,需要运行此应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆