无法在 IntelliJ Idea IDE 中解析符号 javafx.application

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27178895/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 03:56:38  来源:igfitidea点击:

cannot resolve symbol javafx.application in IntelliJ Idea IDE

javaintellij-ideajavafx

提问by rob111

I tried to create a JavaFXapplication in IntelliJ Idea IDE but I got compile error that said:

我试图在 IntelliJ Idea IDE 中创建一个JavaFX应用程序,但出现编译错误,提示:

java: package javafx.application does not exist.

java:包 javafx.application 不存在。

I have changed the Project SDK and the Project Language Level to Java 8, reloaded the project but it didn't help. Then I checked if JavaFX plugin was enabled in the settings.

我已将项目 SDK 和项目语言级别更改为 Java 8,重新加载项目但没有帮助。然后我检查了是否在设置中启用了 JavaFX 插件。

The search on Google and StackOverflow didn't give me more ideas of what is wrong. Thank for any help in advance.

在 Google 和 StackOverflow 上的搜索并没有给我更多关于什么是错误的想法。提前感谢您的任何帮助。

P.S. I am using IntelliJ Idea 14.0 with java8.1.0_25 on archlinux OS.

PS我在archlinux操作系统上使用IntelliJ Idea 14.0和java8.1.0_25。

采纳答案by Ryan J

As indicated here, JavaFX is no longer included in openjdk.

如图所示这里,JavaFX是不再包含在OpenJDK的。

So check, if you have <Java SDK root>/jre/lib/ext/jfxrt.jaron your classpath under Project Structure -> SDKs -> 1.x -> Classpath? If not, that could be why. Try adding it and see if that fixes your issue, e.g. on Ubuntu, install then openjfx package with sudo apt-get install openjfx.

所以检查一下,如果你<Java SDK root>/jre/lib/ext/jfxrt.jar在你的类路径下Project Structure -> SDKs -> 1.x -> Classpath?如果没有,这可能就是原因。尝试添加它,看看是否能解决您的问题,例如在 Ubuntu 上,安装然后使用 .openjfx 包sudo apt-get install openjfx

回答by patterkyle

You need to download the java-openjfx package from the official Arch Linux repos. (Also, make sure you have the openjdk8-openjdk package). After doing that, open your project in Intellij and go to Project-Structure -> SDKs -> 1.8 -> Classpath and try removing the old JDK you had and clicking on the directory for the new JDK that will now contain jfxrt.jar.

您需要从官方 Arch Linux 存储库下载 java-openjfx 包。(另外,确保你有 openjdk8-openjdk 包)。之后,在 Intellij 中打开您的项目并转到 Project-Structure -> SDKs -> 1.8 -> Classpath 并尝试删除您拥有的旧 JDK,然后单击现在将包含 jfxrt.jar 的新 JDK 的目录。

回答by Rok Strni?a

You can use the one that comes with IntelliJ: <intellij>/jre64/lib/ext/jfxrt.jar.

您可以使用 IntelliJ 附带的一个:<intellij>/jre64/lib/ext/jfxrt.jar.

回答by Himel Rana

This should be your perfect solution. Try and enjoy. If some command does not work properly that means if you get any error, try to solve it yourself. I have given you the main thing you need. If your application is in a different location, or your system architecture is different, solve it yourself. It's very easy to do it. Just follow my given solution.

这应该是您的完美解决方案。尝试和享受。如果某些命令无法正常工作,这意味着如果您遇到任何错误,请尝试自己解决。我已经给了你你需要的主要东西。如果您的应用程序位于不同的位置,或者您的系统架构不同,请自行解决。这很容易做到。只需按照我给定的解决方案。

Step 0:

第 0 步:

sudo apt-get install openjdk-8-jre

Step: 1

第1步

sudo apt-get install openjfx

Step 2:

第2步:

sudo cp /usr/share/java/openjfx/jre/lib/ext/* /usr/lib/jvm/java-1.8.0-openjdk-amd64/lib

Step 3:

第 3 步:

sudo cp /usr/share/java/openjfx/lib/* /usr/lib/jvm/java-1.8.0-openjdk-amd64/lib

Step 4:

第四步:

sudo chmod 777 -R /usr/lib/jvm/java-1.8.0-openjdk-amd64

now open a new project or rebuild your project. Good luck.

现在打开一个新项目或重建您的项目。祝你好运。

回答by Raphael S

You might have a lower project language level than your JDK.

您的项目语言级别可能低于 JDK。

Check if: "Projeckt structure/project/Project-> language level" is lower than your JDK. I had the same problem with JDK 9 and the language level was per default set to 6.

检查:“项目结构/项目/项目-> 语言级别”是否低于您的 JDK。我在 JDK 9 上遇到了同样的问题,语言级别默认设置为 6。

I set the Project Language Level to 9 and everything worked fine after that.

我将项目语言级别设置为 9,之后一切正常。

You might have the same issue.

你可能有同样的问题。

回答by user10899964

Another way to resolve the problem : Click the left mouse's button on the project folder in the project structure at the left, and click on "open module settings" in the list of actions In the new windows, click on SDKs which is under the menu title "Platform settngs" Then check on the "Classpath" list if you can find the jfxrt plugin path, if not, click on the + symbol on the right and select the repertory of the jfxrt plugin (C:\Program Files\Java\jdk1.8.0\jre\lib\ext\jfxrt.jar on my desktop)

另一种解决问题的方法:在左侧项目结构中的项目文件夹上单击鼠标左键,然后在操作列表中单击“打开模块设置”在新窗口中,单击菜单下的SDKs title "Platform settngs" 然后查看"Classpath"列表是否能找到jfxrt插件路径,如果没有,点击右边的+号,选择jfxrt插件的reperory(C:\Program Files\Java\ jdk1.8.0\jre\lib\ext\jfxrt.jar 在我的桌面上)

回答by Peter Lamberg

Sample Java application:

示例 Java 应用程序:

I'm crossposting my answer from another questionhere since it is related and also seems to solve the problem in the question.

我在这里交叉发布另一个问题的答案,因为它是相关的,并且似乎也解决了问题中的问题。

Here is my example project with OpenJDK 12, JavaFX 12 and Gradle 5.4

这是我使用 OpenJDK 12、JavaFX 12 和 Gradle 5.4 的示例项目

  • Opens a JavaFX window with the title "Hello World!"
  • Able to build a working runnable distribution zip file (Windows to be tested)
  • Able to open and run in IntelliJ without additional configuration
  • Able to run from the command line
  • 打开一个标题为“Hello World!”的 JavaFX 窗口
  • 能够构建一个有效的可运行分发 zip 文件(Windows 待测试)
  • 无需额外配置即可在 IntelliJ 中打开和运行
  • 能够从命令行运行

I hope somebody finds the Github project useful.

我希望有人发现 Github 项目很有用。

Instructions for the Scalacase:

Scala案例说明:

Additionally below are instructions that work with the Gradle Scalaplugin, but don't seem work with Java. I'm leaving this here in case somebody else is also using Scala, Gradle and JavaFX.

此外,以下是适用于 Gradle Scala插件的说明,但似乎不适用于 Java。我把这个留在这里以防其他人也在使用 Scala、Gradle 和 JavaFX。

1) As mentioned in the question, the JavaFX Gradle plugin needs to be set up. Open JavaFX has detailed documentation on this

1)如问题中所述,需要设置JavaFX Gradle插件。 Open JavaFX 有关于这个的详细文档

2) Additionally you need the the JavaFX SDK for your platformunzipped somewhere. NOTE: Be sure to scroll down to Latest releasessection where JavaFX 12is (LTS 11 is first for some reason.)

2) 此外,您需要将适用于您平台的 JavaFX SDK 解压缩到某处。注意:请务必向下滚动到JavaFX 12所在的最新版本部分(由于某种原因,LTS 11 是第一个。)

3) Then, in IntelliJ you go to the File -> Project Structure -> Libraries, hit the ?-button and add the libfolder from the unzipped JavaFX SDK.

3) 然后,在 IntelliJ 中,您转到File -> Project Structure -> Libraries,点击 ? 按钮并lib从解压缩的 JavaFX SDK添加文件夹。

For longer instructions with screenshots, check out the excellent Open JavaFX docs for IntelliJI can't get a deep link working, so select JavaFX and IntelliJand then Modular from IDEfrom the docs nav. Then scroll down to step 3. Create a library. Consider checking the other steps too if you are having trouble.

有关屏幕截图的更长说明,请查看IntelliJ的优秀Open JavaFX 文档我无法获得深层链接工作,因此请选择JavaFX and IntelliJ,然后Modular from IDE从文档导航中选择。然后向下滚动到步骤3. Create a library。如果您遇到问题,请考虑检查其他步骤。

It is difficult to say if this is exactly the same situation as in the original question, but it looked similar enough that I landed here, so I'm adding my experience here to help others.

很难说这是否与原始问题中的情况完全相同,但它看起来足够相似以至于我来到这里,所以我在这里添加我的经验以帮助其他人。

回答by Stone

In IntelliJ Idea,

在 IntelliJ Idea 中,

Check the following things are configured properly,

检查以下东西是否配置正确,

Step 1:

第1步:

File -> Setting -> Plugins -> search javafx and make sure its enabled.

文件 -> 设置 -> 插件 -> 搜索 javafx 并确保其已启用。

Step 2: Project Structure (Ctrl+Shift+Alt+s)

第 2 步:项目结构(Ctrl+Shift+Alt+s)

Platform Settings -> SDKs -> 1.8 -> Make sure Classpath should have "jre\lib\ext\jfxrt.jar"

平台设置 -> SDKs -> 1.8 -> 确保类路径应该有“jre\lib\ext\jfxrt.jar”

Step 3:

第 3 步:

Project Settings -> Project -> Project SDK - should be selected 1.8

项目设置 -> 项目 -> 项目 SDK - 应选择 1.8

Project Settings -> Project -> Project language level - configured as 8

项目设置 -> 项目 -> 项目语言级别 - 配置为 8

Ubuntu: If not found jfxrt.jar in your SDKs then install sudo apt-get install openjfx

Ubuntu:如果在您的 SDK 中找不到 jfxrt.jar,则安装sudo apt-get install openjfx

回答by Djak aim

I had the same problem, in my case i resolved it by:

我遇到了同样的问题,就我而言,我通过以下方式解决了它

1) going to File-->Project Structure---->Global libraries 2) looking for jfxrt.jar included as default in the jdk1.8.0_241\lib (after installing it) 3)click on + on top left to add new global library and i specified the path of my jdk1.8.0_241 Ex :(C:\Program Files\Java\jdk1.8.0_241).

1)转到文件-->项目结构-->全局库 2)寻找jdk1.8.0_241\lib中默认包含的jfxrt.jar(安装后) 3)点击左上角的+添加新的全局库,我指定了 jdk1.8.0_241 Ex 的路径:(C:\Program Files\Java\jdk1.8.0_241)。

I hope this will help you

我希望这能帮到您