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

Viewed 168205

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?

35 Answers

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.

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.

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

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.

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)


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.

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!

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.

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

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

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

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

[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

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.

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

Resolved by simply "Refresh All Gradle Projects"

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.

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.

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.

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

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

Related