4

I have started a new Java 11 Project with the newest Version of the IntelliJ IDEA Community Edition (IntelliJ IDEA 2018.3.5).

Everything seemed to work just fine for a while, but then some MethodCalls from imported modules were not recognised without any obvious reason. I've already tried invalidating the cache, but it did nothing. I'm also using maven 3.6.0 as I stumbled upon a post which suggested that the maven version that comes with said IDEA is not compatible with Java 11.

More specifically I tried using the method Optional.ofNullable() (same with of() or any other method of this class) which IntelliJ even proposed with AutoComplete. After auto-completion however IntelliJ seems to have forgotten it just now knew the method and proclaims: "Cannot find symbol: class ofNullable". The funny thing is: I can even Ctrl-Click Optional to be directed to the class and see that the method is actually there.

I'm at a loss. Has somebody experienced a similar problem?

Richard Neish
  • 8,414
  • 4
  • 39
  • 69
Sebi
  • 49
  • 3
  • 1
    `File > Project Structure > Project` What are the SDK and language level set to? – Michael Mar 19 '19 at 12:59
  • Likewise, `File > Project Structure > Modules > {your module}` what is the language level set to? – Michael Mar 19 '19 at 12:59
  • In a Maven project, IntelliJ will automatically change these based on `source` / `target` options for the maven compiler plugin. – Michael Mar 19 '19 at 13:01
  • SDK and language level are both set to 11 (SDK: C:\Program Files\Java\jdk-11.0.2, language level: SDK - default(11 - local variable syntax for lambda representation)) and Modules language level is also 11 (Project Default (11 - local variable syntax for lambda representation)) – Sebi Mar 19 '19 at 13:19
  • @Sebi What's your IntelliJ version? Could it be that you are using a very old version which doesn't support Java 11. – Karol Dowbecki Mar 19 '19 at 13:21
  • IntelliJ IDEA 2018.3.5 I just recently downloaded it after I set up a new computer – Sebi Mar 19 '19 at 13:34
  • If you are using Maven, check to make sure the pom.xml is not overriding the compiler source and target versions. https://stackoverflow.com/questions/38882080/specifying-java-version-in-maven-differences-between-properties-and-compiler-p – AlexC Mar 19 '19 at 13:55
  • @Sebi if you just downloaded it, should the version be at 2019+ ? – matt Feb 20 '20 at 12:39

1 Answers1

4

I have solved this problem as follows for the Spring boot project with the Gradle build tool.
IntelliJ-Idea version should support Java-11(related JAVA version).
Checks to perform from Bigger scope to narrower scope

  • Check IDE support
  • Check Build tool support and config
  • Check Project settings
  • Check Modules settings
  • Check application run settings
  1. Add Java-11 SDK in Idea-IDE enter image description here

  2. Change Gradle JVM to Java-11
    Preferences --> build,Execution,Deployment --> BuildTools --> Gradle
    Old Intellij-Idea
    Old Intellij Idea New Intellij-Idea
    gradle config

  3. Change Project SDK and Language Level to Java-11 enter image description here

  4. Change Module Language Level to Java-11 enter image description here

  5. Change modules SDK to Java-11 enter image description here

  6. Application run configuration to Java-11 enter image description here

dkb
  • 4,389
  • 4
  • 36
  • 54