Why so red? IntelliJ seems to think every declaration/method cannot be found/resolved

前端 未结 28 1214
予麋鹿
予麋鹿 2020-12-12 11:22

I just installed and re-installed IntelliJ. Every Java file is coming up RED. I checked the JDK; it is at 1.6.##. The maven clean install build worked just fine

相关标签:
28条回答
  • 2020-12-12 11:55

    Check that you have a proper JVM SDK setting in IntelliJ Properties. If invalidate-cache-and-restart isn't enough, check that your are using the proper JVM SDK, such as Java 1.7.

    Look in: Preferences -> IDE Settings -> Scala -> JVM SDK

    Or right click your project -> Open Module Settings -> Project Settings -> Project -> Project SDK -> (Set to Java 1.7)

    Open Module Settings -> Platform Settings -> SDKs -> (Ensure that there is a Java 1.7, otherwise you'll need to add it)

    If you've made a change, then it's probably best to re-run Invalidate Cache & Restart.

    0 讨论(0)
  • 2020-12-12 11:57

    Yet another work around!One of the solutions, which suggested clicking Alt Enter didn't have the Setup JDK for me, but Add ... to classpathworked.

    0 讨论(0)
  • 2020-12-12 11:58

    I experienced this when I updated my JDK manually and removed the previous JDK

    Red keywords

    Solution

    • In the IntelliJ editor, click on the red keyword (Integer for example) and press ALT + ENTER (or click the light bulb icon)
    • select Setup JDK from the intentions menu

    IntelliJ intentions menu

    • click on Configure

    Project SDK selection dialog

    • In my case, the JDK path was incorrect (pointed on /opt/jdk1.7.0_51 instead of /opt/jdk1.7.0_65)

    Broken Configure SDK dialog

    • Click on the ... and browse to the right JDK path

    Fixed Configure SDK dialog

    • Let's clear the cache:

    IntelliJ File menu

    And everything should be back to life :)

    No red keywords

    0 讨论(0)
  • 2020-12-12 11:58

    I had this problem on a fresh install of IDEA. I thought it had brought its own JDK or would be able to find the one already on the machine, but apparently not (not sure what the checkbox in the install dialog did, now). When I clicked on the lightbulb and clicked the "Setup JDK" button and then clicked "Configure," it revealed that it was trying to get the JDK from

    C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.1\jre64

    I browsed around, trying a few folders in the JetBrains tree, but at least the dialog was smart enough not to let me apply any (including the original), saying they were not valid locations for a JDK. So I browsed over to the Java tree and tried that, and it accepted this:

    C:\Program Files\Java\jdk1.8.0_40

    After I OK'ed the config, it didn't appear to have worked; so I went to try invalidating the IDEA cache and restarting (as described in other answers), and it told me that I had background tasks running. So I canceled out of the invalidation, and while I was doing that, whatever recompilation or database updating it was doing completed, and all the red in the edit window went away. So it takes a few seconds (at least) for the JDK config to settle out.

    0 讨论(0)
  • 2020-12-12 11:59

    For me it was the JDK that was not set up correctly. I found a solution that I documented here: https://stackoverflow.com/a/40127871/808723

    0 讨论(0)
  • 2020-12-12 12:01

    Using IntelliJ 2019.3 and a Gradle project dependent on my own Gradle project, the only thing that fixed it for me was Reimport All Gradle Projects under View -> Tool Windows -> Gradle (and refresh button).

    Before that I tried restarting IDE, I tried "Invalidate Caches and Restart", I tried Rebuild project, neither helped.

    0 讨论(0)
提交回复
热议问题