Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 647
starsuper Avatar asked Sep 26 '18 05:09

starsuper


People also ask

Why does it say Cannot find symbol in Java?

The “cannot find symbol” error occurs mainly when we try to reference a variable that is not declared in the program which we are compiling, it means that the compiler doesn't know the variable we are referring to.


2 Answers

Try setting compiler target bytecode version to 11.

Go to Settings - Build, Execution, Deployment - Compiler - Java compiler and set target bytecode version of your module to 11

like image 194
Denis Zavedeev Avatar answered Oct 13 '22 07:10

Denis Zavedeev


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

like image 24
Rostislav Krasny Avatar answered Oct 13 '22 05:10

Rostislav Krasny