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

JavaMavenIntellij Idea

Java Problem Overview


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?

Java Solutions


Solution 1 - Java

IntelliJ sometimes gets confused all by itself, even without the external changes Korgen described (though that is a good way to consistently reproduce it).

Click File -> Synchronize, and IntelliJ should see that everything is okay again.

If that doesn't work, IntelliJ's caches might be corrupt (this used to happen a lot more often than it does now); in that case, regenerate them by

Clicking File -> Invalidate Caches and restarting the IDE

(though loading the project will take a while while the caches are recreated).

Solution 2 - Java

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

Solution 3 - Java

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

Solution 4 - Java

I had the same problem after changing JDK from 1.6 to 1.7 in my pom.xml and setting Maven 3 path + JDK project settings to 1.7.

What did it for me was => File -> Invalidate Caches and Restart

PS: problem occured again, so i just reimported the full project after deleting the .idea folder and now it works fine as usual :)

Solution 5 - Java

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.

Solution 6 - Java

If you're still getting this error, even after you've tried all the other suggestions on this question, you have checked all your JDK, Maven settings, invalidated cache, synchronized your workspace and restarted, but things still aren't working for you, then go to your project directory and delete the entire .idea folder. Restart your IntelliJ; all the files under .idea will be created freshly which reflects the current situation.

At least, this worked for me.

Solution 7 - Java

My problem solved by changing jdk to default , like this. Open Jdk was installed but don't know why intellij set configuration to java-8-openjdk-amd64. This was the problem.I have changed to default-java and no more red error.

enter image description here

Solution 8 - Java

This is if you see Java classes in red and get this error, "Cannot resolve symbol".

If you're importing projects into IntelliJ and none of the above solutions worked for you then give this a try. This is what worked for me when everything else failed.

Go to to your project folder and rename/delete the .idea folder which has the idea settings for your project. This would have been created from your old IntelliJ version. Once you have renamed/deleted the .idea folder, import your project into IntelliJ. You should not see any errors for your Java classes now. Hope this helped.

Solution 9 - Java

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.

Solution 10 - Java

There can be various reasons. you can apply following solution in order. Follow next solution if before one doesn't work.

1. Check the If project is using proper version of JDK (File -> Project Structure -> Project -> Project sdk )
2. Invalidate cache -> (File -> Invalidate cache)
3. Delete .idea folder and Invalidate cache. (present in project directory)
4. Delete .idea & *.iml file and Invalidate cache. (present in project directory)


Solution 11 - Java

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.

Solution 12 - Java

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.

Solution 13 - Java

Tried invalidating cache, reimporting the project, switching to built-in Maven, removing the .m2 folder and its parts, - nothing worked. After I had completely broken Maven (while it had built the project successfully before, now it couldn't anymore), I had to reinstall it from scratch. It helped!

Solution 14 - Java

I had the same problem.

In my case the problem was with maven home directory and user settings file in Intellij Settings under Maven. I had installed Maven not in the default directory and I had also changed the location of the settings.xml file. This should also be changed in the IntelliJ Settings.

Hope this helps also.

Solution 15 - Java

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.

Solution 16 - Java

I spent most of a day trying all the solutions here, but nothing seemed to work. The only thing that worked for me was to completely uninstall IntelliJ and install it again. However, for me, when I deleted IntelliJ from the Application folder, the problem returned as soon as I re-installed it. What I finally had to do was to use App Cleaner to completely remove IntelliJ and all the config and settings files. After I did that and then reinstalled IntelliJ, the problem finally went away. See How to uninstall IntelliJ on a Mac

Solution 17 - Java

For 2020.1.4 Ultimate edition, I had to do the following

View -> Maven -> Generate Sources and Update Folders For all Projects

The issue for me was the libraries were not getting populated with mvn -U clean install from the terminal.

enter image description here

Solution 18 - Java

If all the answers do not work try to update Lombok dependency and install the Lombok plugin in Intellij.

For install/update Lombok plugin

  • Press Alt + Ctrl + S
  • Plugins
  • Search Lombok install/update
  • File (Top Left)
  • Invalidate Caches..
  • Invalidate and restart

Solution 19 - Java

I had to first remove the .idea folder and then restart IntelliJ using the invalidate caches method. Only invalidate caches was not enough

Solution 20 - Java

I was trying to use all the advices above, but unfortunately no one helped me. So finally I've decided to delete my intelij workspace and create the new one - it helped :) But earlier I was also doing cleaning the cache, reimporting maven projects, cleaning projects and rebuilding them.

Solution 21 - Java

I had the same problem and after trying all of the above suggestions, it turned out that my IntelliJ installation had not picked up my JAVA_HOME system variable, and it had no SDK/JDK set.

I fixed it by following these instructions: Configuring Global, Project and Module SDKs

Solution 22 - Java

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

Solution 23 - Java

The issue was that the file I was trying to import was so large that IntelliJ wouldn't run any CodeInsights on it.

Setting the idea.max.intellisense.filesize option to a higher value as per the instructions on this answer resolved my issue.

Solution 24 - Java

I had the same issue I was using JDK 1.9 with IntelliJ 14, I solved reinstalling Java with latest version of JDK 1.8(1.8.0_161 in this case)

I also removed the 1.9 version from

HKEY_CURRENT_USER\Software\JavaSoft\JRE\Security Baseline

Solution 25 - Java

I had the same issue, what fixed it for me was:

Go to File>Setting>Maven, I set the Maven home directory, settings file and local repo.

Go to Maven Projects and click on Reimport All Maven Projects

enter image description here

This did the trick!

Solution 26 - Java

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.

Solution 27 - Java

Try to delete the .IntelliJIdea15(depends on version) from C:\Users\Username

When you start IntelliJ it will create the folder again.

Solution 28 - Java

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

Solution 29 - Java

Resolved by simply "Refresh All Gradle Projects"

Solution 30 - Java

I could not get any of these solutions to work for me. I had to manually go to every method/class that I got the error on and import it manually. After that everything was fine.

Solution 31 - Java

I face the same issue when upgraded Intellij version. It was resolved for me by using old maven than the one bundled with the new Intellij.

Solution 32 - Java

None of the answers here helped me, but I did manage to solve it.
My project structure looks like this:

-- myprojectname
    -- .idea
    -- backend
    -- frontend

In my backend folder, every java file came up red. I had to mark the backend folder as a Module (folder with a blue square enter image description here). Follow these steps:

  • Go to File -> Project Structure -> Project Settings -> Modules

  • Select Add enter image description here -> Import Module

  • Find and select your pom.xml or build.gradle file -> OK

  • Select the new module and mark src/main/java directory as 'Sources' and src/main/resources/ as 'Resources'. Do similarly with the test folder, mark them as 'Tests' and 'Test Resources'.

  • Select Apply -> OK

If you get a notification 'Safe mode, limited functionality', on the notification select 'Trust project...'. After a couple of seconds everything should be ok.

Solution 33 - Java

I faced this issue when Intellij updated from 2021.1 to 2021.2. In my case, none of the solutions worked. I'm using ant as the build tool. Try invalidate cache/restart if that did not solve the problem follow this method. File->Project Structure-> Modules. Under the Dependencies tab re-arrange the dependencies depending on your project and apply the changes. enter image description here

Solution 34 - Java

I wonder if this may sometimes be caused by initially "importing" with File > Open... instead of File > New > <any Project option from here>, on the project (that otherwise ends up with red project references).

When choosing the New route, I usually already have the projected cloned/checked-out from Version Control to my local (with the IntelliJ) already, so I then in that case choose Project from Existing Sources...

enter image description here

Subsequently, IntelliJ gives the option to Import project from external model, in which there is a Maven option - I wonder if choosing that decreases the chance that the project references end up in red (to maybe give Maven more of a chance to "understand" the project in the IDE to begin with) - I will try to experiment with this and report back here...

enter image description here

Solution 35 - Java

[After ensuring to first mvn clean install (as stated in Question) ...]

(I'd say try this as the [in-between] second solution in Ritu Gupta's nice solution attempt order Answer)

I'm not sure if it is one or both of the further-below [1, 2] that sometimes help me... Both of these are IntelliJ-Maven options, which can be reached from either [A, B]:

A] View -> Tool Windows -> Project -> right-click on any of {project root, OR pom.xml, OR within pom.xml itself} -> Maven

enter image description here

enter image description here

B] View -> Tool Windows -> Maven

enter image description here

enter image description here


1]

(if using A]^) Reload Project

(possibly the new name of the option in Korgen's Answer)

enter image description here

(if using B]^) Reload All Maven Projects

enter image description here

This is also reachable with IntelliJ Shift + Shift shortcut:

enter image description here


2] Generate Sources And Update Folders For All Projects

(essentially user1599755's Answer)

(if using A]^)

enter image description here

(if using B]^)

enter image description here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestioniCodeLikeImDrunkView Question on Stackoverflow
Solution 1 - JavaMatt LeidholmView Answer on Stackoverflow
Solution 2 - JavaJossef Harush KadouriView Answer on Stackoverflow
Solution 3 - JavaKorgenView Answer on Stackoverflow
Solution 4 - Java0x126View Answer on Stackoverflow
Solution 5 - JavaParantap SharmaView Answer on Stackoverflow
Solution 6 - JavaShepherdView Answer on Stackoverflow
Solution 7 - JavamnhmiluView Answer on Stackoverflow
Solution 8 - JavaArthasView Answer on Stackoverflow
Solution 9 - JavaPeter DietzView Answer on Stackoverflow
Solution 10 - JavaRitu GuptaView Answer on Stackoverflow
Solution 11 - JavapastafarianView Answer on Stackoverflow
Solution 12 - JavaNSonmezView Answer on Stackoverflow
Solution 13 - JavaKatia SavinaView Answer on Stackoverflow
Solution 14 - JavaElioView Answer on Stackoverflow
Solution 15 - JavaSajjonView Answer on Stackoverflow
Solution 16 - JavaRoss MillsView Answer on Stackoverflow
Solution 17 - Javauser1599755View Answer on Stackoverflow
Solution 18 - JavaRinkesh MeharView Answer on Stackoverflow
Solution 19 - Javauser15013406View Answer on Stackoverflow
Solution 20 - JavaMarcin ErbelView Answer on Stackoverflow
Solution 21 - JavavphilipovView Answer on Stackoverflow
Solution 22 - JavaGameScriptingView Answer on Stackoverflow
Solution 23 - JavaecnepsnaiView Answer on Stackoverflow
Solution 24 - JavaSamView Answer on Stackoverflow
Solution 25 - JavaMohith MarattView Answer on Stackoverflow
Solution 26 - JavaBlair HoughtonView Answer on Stackoverflow
Solution 27 - JavaSudeepView Answer on Stackoverflow
Solution 28 - JavaSuren KonathalaView Answer on Stackoverflow
Solution 29 - JavaAlexPesView Answer on Stackoverflow
Solution 30 - JavaSovietFrontierView Answer on Stackoverflow
Solution 31 - JavaVishal TView Answer on Stackoverflow
Solution 32 - JavaAndriView Answer on Stackoverflow
Solution 33 - JavaGAGAN GOWDAView Answer on Stackoverflow
Solution 34 - JavacellepoView Answer on Stackoverflow
Solution 35 - JavacellepoView Answer on Stackoverflow