Java 无法在 IntelliJ 中使用 jdk 11 进行编译,找不到符号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/52510671/
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
Can't compile with jdk 11 in IntelliJ, cannot find symbol
提问by starsuper
I set the JDK 11, it compiles until I use the new method of Java 11 isBlank()
of a String when I use that method this error appears when compiling, I tried cleaning the JDK installations, cleaning caches from IntelliJ, rebuilding but nothing helps. The error is:
我设置了 JDK 11,它会一直编译,直到我使用isBlank()
字符串的 Java 11 的新方法为止,当我使用该方法时,编译时出现此错误,我尝试清理 JDK 安装,从 IntelliJ 清理缓存,重建但没有任何帮助。错误是:
回答by Pim Hazebroek
You can use JDK 11 to compile but if you compile against an older version of java, it cannot find that method.
您可以使用 JDK 11 进行编译,但如果您针对旧版本的 Java 进行编译,则无法找到该方法。
Go to File > Project Structure -> Project
and check the project language level as shown by the arrow in the picture below:
转到File > Project Structure -> Project
并检查项目语言级别,如下图箭头所示:
Not working with project language level 10:
Working fine with project language level 11:
Note that I have the following Java Compiler settings (default settings for a fresh new project using IntelliJ 2018.3):
The project bytecode version is same as language level!
请注意,我有以下 Java 编译器设置(使用 IntelliJ 2018.3 的全新项目的默认设置):项目字节码版本与语言级别相同!
回答by caco3
Try setting compiler target bytecode version to 11.
尝试将编译器目标字节码版本设置为 11。
Go to Settings
- Build, Execution, Deployment
- Compiler
- Java compiler
and set target bytecode versionof your moduleto 11
去Settings
- Build, Execution, Deployment
- Compiler
-Java compiler
并设置目标字节代码的版本你的模块11
回答by Rostislav Krasny
You should check following things:
您应该检查以下事项:
- You've JDK11 defined as one of the SDKs:
- Your project's default SDK is JDK11 and your projects default language level is 11:
- Your module language level is also 11.
And if you use Maven, check that your compiler plugin "source" and "target" properties in your pom.xml
are 11. Your module language level configuration is imported from that pom.xml
configuration in such a case
如果您使用 Maven,请检查您的编译器插件“源”和“目标”属性pom.xml
是否为 11。pom.xml
在这种情况下,您的模块语言级别配置是从该配置导入的
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
or
或者
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
In case your pom.xml
had wrong source or target level you may need to do Right-click | Maven | Reimport after changing that pom.xml
. In case you use Gradle you should check that you have a similar configuration.
如果您pom.xml
有错误的源或目标级别,您可能需要执行右键单击 | 马文 | 更改后重新导入pom.xml
。如果您使用 Gradle,您应该检查您是否有类似的配置。
Tested with Maven 3.5.4 in IntelliJ IDEA 2018.2.4
在 IntelliJ IDEA 2018.2.4 中使用 Maven 3.5.4 进行测试
回答by Omar Faroque Anik
回答by batchmode
I had a similar problem. Got symbol not foundfor a Java 11 feature. Though everything was set to 11 already.
我有一个类似的问题。有没有发现标志为Java 11功能。虽然一切都已经设置为 11。
The solution was that in my Idea settings the Gradle JVM was set to JDK 8. (because I added JDK 11 later)
解决方案是在我的 Idea 设置中将 Gradle JVM 设置为 JDK 8。(因为我后来添加了 JDK 11)
As sourceCompatibilty
and targetCompatibility
where not set in my build.gradle the gradle daemon (started from Idea) was running and compiling with JDK 8. These properties where dynamically set to 8 (or 1.8).
作为sourceCompatibilty
与targetCompatibility
凡在我的build.gradle没有设置gradle这个守护进程(从理念开始)正在运行,并与JDK 8,其中动态设置为8(或1.8)这些属性进行编译。
Telling Idea to set JVM for Gradle to 11 was my solution:
告诉 Idea 将 Gradle 的 JVM 设置为 11 是我的解决方案: