尝试在intellij jre11上运行javafx程序

时间:2018-10-19 10:49:21

标签: java javafx javafx-11

我已经安装了intellij,并且试图打开一个新的javafx,但是我无法运行它(即使是默认的基本Javafx也应该打开一个简单的窗口) 我正在使用jdk 11(我必须这样做),所以我下载了javafx,如本文所述:

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

但是我得到这个错误

"C:\Program Files\Java\jdk-11.0.1\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA
2018.2.5\lib\idea_rt.jar=59874:C:\Program Files\JetBrains\IntelliJ IDEA 2018.2.5\bin" -Dfile.encoding=UTF-8 -classpath "C:\Users\itzik\IdeaProjects\untitled3\out\production\untitled3;C:\Program Files\Java\javafx-sdk-11\lib\src.zip;C:\Program Files\Java\javafx-sdk-11\lib\javafx-swt.jar;C:\Program Files\Java\javafx-sdk-11\lib\javafx.web.jar;C:\Program Files\Java\javafx-sdk-11\lib\javafx.base.jar;C:\Program Files\Java\javafx-sdk-11\lib\javafx.fxml.jar;C:\Program Files\Java\javafx-sdk-11\lib\javafx.media.jar;C:\Program Files\Java\javafx-sdk-11\lib\javafx.swing.jar;C:\Program Files\Java\javafx-sdk-11\lib\javafx.controls.jar;C:\Program Files\Java\javafx-sdk-11\lib\javafx.graphics.jar" sample.Main


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

Process finished with exit code 1

如果我尝试在解决方案中执行此行

  

然后在“运行”->“编辑配置”->“虚拟机选项”中,输入:   --module-path =“ C:\ Program Files \ Java \ javafx-sdk-11 \ lib” --add-modules = javafx.controls

错误更改为:

"C:\Program Files\Java\jdk-11.0.1\bin\java.exe" "--module-path=C:\Program Files\Java\javafx-sdk-11\lib"
--add-modules=javafx.controls "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA
2018.2.5\lib\idea_rt.jar=59984:C:\Program Files\JetBrains\IntelliJ IDEA 2018.2.5\bin" -Dfile.encoding=UTF-8 -classpath "C:\Users\itzik\IdeaProjects\untitled3\out\production\untitled3;C:\Program Files\Java\javafx-sdk-11\lib\src.zip;C:\Program Files\Java\javafx-sdk-11\lib\javafx-swt.jar;C:\Program Files\Java\javafx-sdk-11\lib\javafx.web.jar;C:\Program Files\Java\javafx-sdk-11\lib\javafx.base.jar;C:\Program Files\Java\javafx-sdk-11\lib\javafx.fxml.jar;C:\Program Files\Java\javafx-sdk-11\lib\javafx.media.jar;C:\Program Files\Java\javafx-sdk-11\lib\javafx.swing.jar;C:\Program Files\Java\javafx-sdk-11\lib\javafx.controls.jar;C:\Program Files\Java\javafx-sdk-11\lib\javafx.graphics.jar" sample.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: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 @0x555df7da) 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 @0x555df7da   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

Process finished with exit code 1

我试图解决此问题超过2个小时,但仍无法在网上搜索= \ 试图在项目结构中将语言级别设置为8 \ 10 \ 11,但仍然无效

带有hello world的常规java程序可以工作,只是java fx可以解决问题...

2 个答案:

答案 0 :(得分:0)

如果在Java 11中使用JavaFX,则需要添加JavaFX jar文件。

JavaFX在JDK 10之后与JDK分离,因此请下载JavaFX for Java 11并将其添加为外部库。

答案 1 :(得分:0)

在运行中找到了解决方案->编辑配置---> VM选项

-module-path =“ C:\ Program Files \ Java \ javafx-sdk-11 \ lib” --add-modules = javafx.controls --add-exports = javafx.graphics / com.sun.javafx .util = ALL-UNNAMED --add-modules javafx.controls --add-exports = javafx.graphics / com.sun.javafx.util = ALL-UNNAMED --add-exports = javafx.base / com.sun.javafx .reflect =全部取消--add-exports = javafx.base / com.sun.javafx.beans =全部取消--add-exports = javafx.graphics / com.sun.glass.utils =全部取消- add-exports = javafx.graphics / com.sun.javafx.tk =全部未命名