Why so red? IntelliJ seems to think every declarat

2019-01-20 23:33发布

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.

I'm getting the usual highlighted errors. On every declaration:

Cannot resolve symbol SomeEntityBean/Bean

and on every method:

Cannot resolve method SomeFunction()

How do I fix these false errors?

21条回答
2楼-- · 2019-01-21 00:20

In my case, getter and setter dependencies were coming through lombok plugin (Using java with Spring). And in the new installation of intellij idea, I had not installed the lombok plugin. Installing the lombok plugin fixed it for me.

查看更多
Explosion°爆炸
3楼-- · 2019-01-21 00:22

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.

查看更多
劳资没心,怎么记你
4楼-- · 2019-01-21 00:25

Yet another solution on IntelliJ Ultimate 2018.2

  • Hover over the import marked red
  • Select dropdown arrow on the popup that appears on left (below)
  • Choose "Add library ... to classpath"

enter image description here

查看更多
Animai°情兽
5楼-- · 2019-01-21 00:26

I have IntelliJ IDEA 12.x on the Mac and I use Maven 3 and I get the red highlighting over my code even though the Maven build is fine. None of the above (re-indexing, force import, etc.) worked for me. I had to do the following:

Intellij -> Preferences -> Maven -> Importing
    [ ] Use Maven3 to import projects

I have to check the Maven3 import option and that fixes the issue.

查看更多
beautiful°
6楼-- · 2019-01-21 00:28

IntelliJ sometime gets confused after importing maven projects and then changing poms externally or generating sources outside IntelliJ.

You might want to try a maven->force reimport from within intellij on the project root

查看更多
Anthone
7楼-- · 2019-01-21 00:30

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

查看更多
登录 后发表回答