starsuper
starsuper

Reputation: 461

Can't compile with jdk 11 in IntelliJ, cannot find symbol

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:

enter image description here

Upvotes: 36

Views: 42240

Answers (5)

Denis Zavedeev
Denis Zavedeev

Reputation: 8307

Set compiler target bytecode version to 11:

  1. Settings
  2. Build, Execution, Deployment
  3. Compiler
  4. Java compiler
  5. Set target bytecode version of your module to 11

Upvotes: 69

batchmode
batchmode

Reputation: 61

I had a similar problem. Got symbol not found for a Java 11 feature. Though everything was set to 11 already.

The solution was that in my Idea settings the Gradle JVM was set to JDK 8. (because I added JDK 11 later)

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

Telling Idea to set JVM for Gradle to 11 was my solution:

enter image description here

Upvotes: 6

Omar Faroque Anik
Omar Faroque Anik

Reputation: 2609

For my case, it was not even showing 11 in Project language level. So I had to choose X like below screenshot

enter image description here

Upvotes: 1

Rostislav Krasny
Rostislav Krasny

Reputation: 695

You should check following things:

  1. You've JDK11 defined as one of the SDKs: enter image description here
  2. Your project's default SDK is JDK11 and your projects default language level is 11: enter image description here
  3. Your module language level is also 11. enter image description here

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

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

  1. Your module SDK is Project JDK11 or just JDK11 enter image description here enter image description here

Tested with Maven 3.5.4 in IntelliJ IDEA 2018.2.4

Upvotes: 15

BitfulByte
BitfulByte

Reputation: 4486

You can use JDK 11 to compile but if you compile against an older version of java, it cannot find that method.

Go to File > Project Structure -> Project and check the project language level as shown by the arrow in the picture below:

Not working with project language level 10: Wrong project language level

Working fine with project language level 11: Working project language level

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

Upvotes: 10

Related Questions