使用 Java 9 和 Intellij Idea 的 JavaFX 不存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47376636/
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
JavaFX does not exist using Java 9 and Intellij Idea
提问by user3785637
I am using Intellij Idea to compile a project that uses Maven dependencies and Intellij keeps telling me that my project has 50 something errors because JavaFX does not exist.
我正在使用 Intellij Idea 编译一个使用 Maven 依赖项的项目,Intellij 一直告诉我我的项目有 50 个错误,因为 JavaFX 不存在。
Intellij is not highlighting all the javafx dependencies in my code as errors, it is just that once I press the run and compile the program says that everything in JavaFX does not exists.
Intellij 并没有将我代码中的所有 javafx 依赖项都高亮显示为错误,只是当我按下运行并编译程序时,它会说 JavaFX 中的所有内容都不存在。
I tried to redownload the latest JDK (Java 9.0.1) and that did not fix it. I went into the Default Project Structure and Project Structure to make sure it was using the correct jdk and that did not fix the issue. All the jdks I am using seem to list the javafx packages as included in the project.
我尝试重新下载最新的 JDK(Java 9.0.1),但没有解决。我进入了默认项目结构和项目结构以确保它使用正确的 jdk 并且没有解决问题。我使用的所有 jdks 似乎都列出了项目中包含的 javafx 包。
This is also only an issue for a particular project that I am working on with a friend. We may have to move over all our code into a new project, however I am not sure if that will fix anything.
这也只是我与朋友合作的特定项目的问题。我们可能不得不将所有代码移到一个新项目中,但是我不确定这是否会解决任何问题。
Any suggestions?
有什么建议?
回答by y.bedrov
Try to set project language level to "9" in "Project Structure | Project"
尝试在“项目结构|项目”中将项目语言级别设置为“9”
回答by Fuyang Liu
Okay I see what my problem was.
好的,我知道我的问题是什么。
Besides Try to set project language level to "9" in "Project Structure | Project"
mentioned above, I had a maven setting in some pom.xml looks like this:
除了Try to set project language level to "9" in "Project Structure | Project"
上面提到的,我在一些 pom.xml 中有一个 maven 设置,如下所示:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
and java.version
was defined as 1.8
somewhere above. I just had to change it to 9
和java.version
被定义为1.8
某处之上。我只需要把它改成9
回答by ThirstyCamel
I had this problem after upgrading a JavaFX project from Java 8 to Java 9.
将 JavaFX 项目从 Java 8 升级到 Java 9 后,我遇到了这个问题。
After checking the usual language level settings for the project and module in IntelliJ and the Maven pom, I found the problem was that the module was explicitly set to generate Java 8 bytecode in the Java Compiler preferences.
在检查 IntelliJ 和 Maven pom 中项目和模块的常用语言级别设置后,我发现问题是该模块在 Java 编译器首选项中被显式设置为生成 Java 8 字节码。
Look in Preferences -> Build, Execution, Deployment -> Compiler -> Java Compiler
. Check that Project bytecode version
is unset (or set correctly) and that your module is not listed in Per-module bytecode version
with an incorrect value.
查找范围Preferences -> Build, Execution, Deployment -> Compiler -> Java Compiler
。检查Project bytecode version
是否未设置(或正确设置)并且您的模块未Per-module bytecode version
以不正确的值列出。
回答by Mark Gilmore
File --> Project Structure-->Module
The language level in here as set to 5 for me. Upped it to 9 to allow classes etc and the same error as described above resolved for me.
此处的语言级别为我设置为 5。将其提高到 9 以允许类等,并且与上述相同的错误为我解决。
回答by inetphantom
I missed the modules in my gradle.build. Had to update
我错过了 gradle.build 中的模块。不得不更新
javafx {
version = "11"
modules = [ 'javafx.controls', 'javafx.fxml' ]
}
回答by hariprasad
In Java9+ some modules are not included in JRE/JDK. The solution is to add thore libraries explicitly.
在 Java9+ 中,JRE/JDK 中不包含一些模块。解决方案是显式添加这些库。
For maven pom file for Java9 I used
对于我使用的 Java9 的 maven pom 文件
<!-- https://mvnrepository.com/artifact/org.openjfx/javafx-controls -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.openjfx/javafx-fxml -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>11</version>
</dependency>
Than I can use desired libray for including of TextField.
比我可以使用所需的库来包含 TextField。
import javafx.scene.control.TextField;