35

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

starsuper
  • 451
  • 1
  • 4
  • 4
  • 2
    Please edit the question and share the image completely instead of a link. Do let us know, what version of IntelliJ are you using? – Naman Sep 26 '18 at 06:35
  • @starsuper Did you manage to resolve the issue and if so, how? I am having the same problem and have been struggling to find a solution for 3 days now. None of the answers here have lead to a successful build so far. – Setily Nov 22 '18 at 21:30

5 Answers5

67

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
Denis Zavedeev
  • 7,627
  • 4
  • 32
  • 53
15

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

Rostislav Krasny
  • 577
  • 3
  • 14
  • Note that the OP compile error is showing in the default build tab (compiled with IntelliJ) and not with maven. Good addition though which may be applicable to someone else with similar issues who is using maven. – BitfulByte Sep 27 '18 at 04:47
  • You may still try to build or rebuild your project by IntelliJ IDEA itself, even if your modules are Maven based. – Rostislav Krasny Sep 27 '18 at 09:37
10

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

BitfulByte
  • 4,117
  • 1
  • 30
  • 40
  • 1
    The image in the question reads `javac 11` is used. How do you infer that the project level is not set correctly? Downvoted. – Naman Sep 26 '18 at 06:34
  • @nullpointer given that isBlank() is new in Java 11, not having the project language level set to 11 is the most likely cause of the problem. – jwenting Sep 26 '18 at 06:52
  • 1
    @nullpointer I have added screenshot to demonstrate the effect more clearly. It shows the same error as the OP has encountered. – BitfulByte Sep 26 '18 at 07:44
  • That option is beta in my IDE because the 2018.3 version has yet to be released, it should fix the error when the official update is out, but for now caco3 solution works fine. – starsuper Sep 26 '18 at 16:09
  • Yes I'm using a beta version, however the option for project language level is already available for a couple stable releases, what option are you referring to exactly? – BitfulByte Sep 26 '18 at 18:05
  • Project language level is beta for my current installation but in next versions is available. – starsuper Sep 27 '18 at 03:17
  • What version are you using? – BitfulByte Sep 27 '18 at 04:44
  • 2018.2 in that version it says the 11-Local variable syntax for lambda parameters is beta and you must accept the license, however the program compiles fine by just setting the target byte code to 11, in newer versions all should work fine together. – starsuper Sep 28 '18 at 20:06
6

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

batchmode
  • 61
  • 1
  • 5
  • Finally a working solution. The key was changing the "Gradle JVM". None of the other solutions worked. Had this problem for a long time. – FraK Dec 24 '20 at 12:25
1

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

Omar Faroque Anik
  • 2,531
  • 1
  • 29
  • 42
  • 1
    same with mine as well.. Did you figure out how to get the project language level for java 11? – Seetha Apr 08 '19 at 18:20