无法在IntelliJ中使用jdk 11编译,找不到符号

问题描述 投票:6回答:4

我设置JDK 11,它编译直到我使用String 11的isBlank()的新方法,当我使用该方法编译时出现此错误,我尝试清理JDK安装,从IntelliJ清除缓存,重建但没有任何帮助。错误是:

enter image description here

java intellij-idea java-11
4个回答
8
投票

你应该检查以下事项:

  1. 您已将JDK11定义为SDK之一:enter image description here
  2. 您项目的默认SDK是JDK11,您的项目默认语言级别是11:enter image description here
  3. 您的模块语言级别也是11. enter image description here

如果您使用Maven,请检查pom.xml中的编译器插件“source”和“target”属性是否为11.在这种情况下,您的模块语言级别配置是从该pom.xml配置导入的。

     <properties>
         <maven.compiler.source>11</maven.compiler.source>
         <maven.compiler.target>11</maven.compiler.target>
     </properties>

要么

     <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>

如果您的pom.xml有错误的源或目标级别,您可能需要右键单击| Maven |改变pom.xml后重新进口。如果您使用Gradle,则应检查您是否具有类似的配置。

  1. 您的模块SDK是Project JDK11或JDK11 enter image description here enter image description here

在IntelliJ IDEA 2018.2.4中使用Maven 3.5.4进行测试


6
投票

尝试将编译器目标字节码版本设置为11。

为此,请转到Settings - Build Execution Deployment - Compiler - Java compiler并将模块的目标字节码版本设置为11。


4
投票

您可以使用JDK 11进行编译,但如果您针对旧版本的java进行编译,则无法找到该方法。

转到File > Project Structure -> Project并检查项目语言级别,如下图中的箭头所示:

不使用项目语言10级:Wrong project language level

项目语言11级工作正常:Working project language level

请注意,我有以下Java编译器设置(使用IntelliJ 2018.3的新项目的默认设置):项目字节码版本与语言级别相同! Java compiler settings


0
投票

对于我的情况,它甚至没有在项目语言级别显示11。所以我不得不选择X如下截图

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.