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

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

问题描述

我正在运行 IntelliJ IDEA Ultimate 2018.2.5 ,其中 JDK 11.0.1 来自OpenJFX的 JavaFX 11 。我知道这是一个常见的错误,我尝试了很多提议的修复但没有任何作用。



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

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

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

   - module-path =C:\Program Files\Java\javafx-sdk-11 \lib--add-modules = javafx.controls 

我收到这些错误:

 应用程序启动方法中的异常
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 / jav a.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)
引起:java .lang.RuntimeException:应用程序启动方法中的异常
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
at javafx.graphics/com.sun。 javafx.application.Lau ncherImpl.lambda $ launchApplication $ 2(LauncherImpl.java:195)
at java.base / java.lang.Thread.run(Thread.java:834)
引起:java.lang.IllegalAccessError:class com.sun.javafx.fxml.FXMLLoaderHelper(在未命名的模块@ 0x5fce9dc5中)无法访问类com.sun.javafx.util.Utils(在模块javafx.graphics中)因为模块javafx.graphics不导出com.sun.javafx.util com.sun.javafx.fxml.FXMLLoaderHelper中未命名的模块@ 0x5fce9dc5
。< clinit>(FXMLLoaderHelper.java:38)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.Acces sController.doPrivileged(本地方法)
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更多
异常运行应用程序sample.Main

我尝试重新安装,没有任何运气。我还尝试将
getClass()。getResource(...)更改为 getClass()。getClassLoader()。getResource( ...)或类似父root = FXMLLoader.load(getClass()。getResource(/ sample.fxml)); 但仍然无效。

解决方案

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



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



但现在您必须包含所需的模块/依赖项。 / p>

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

   -  add-modules = javafx.controls 

正如您在中所见JavaDoc javafx.controls 模块依赖于 javafx.graphics java。 base ,但这些模块都没有包含FXML类。



如果你需要FXML类,比如 FXMLLoader ,您需要包含 javafx.fxml 模块:

  --module-path =C:\Program Files\Java\javafx-sdk-11 \lib\ 
--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 Files\Java\javafx-sdk-11\lib" --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 Files\Java\javafx-sdk-11\lib" \
    --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天全站免登陆