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

35

168

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?

Tame answered 24/7, 2012 at 13:40 Comment(2)
possible duplicate of IntelliJ inspection gives "Cannot resolve symbol" but still compiles codeEmelun
@ZacThompson I think you are mostly correct - I would say this Question has the slight difference, of specifying prior-successful mvn clean installKershner
M
262

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

But IDEA now contains a "Repair IDE" menu item in the File menu that will walk you through steps to fix the issues (starting with quick and easy steps and getting progressively more disruptive as it goes on), asking if the problem is fixed after each one. The steps below should no longer be necessary to do directly, since the Repair IDE command will automatically do them only if necessary. They are preserved below for those on older versions:

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).

Muntjac answered 24/7, 2012 at 14:7 Comment(7)
Thank you. Very helpful. I used 'Invalidate Caches' as a last resort and it worked.Odense
Invalidate Caches -> IntelliJ Restart -> Syncronize worked for me. thanks.Lamanna
hopefully eventually you will be able to invalidate and retain the local history?Reseta
Synchronize does not seem to be an option any longer at least as of v2021.1.Doodlesack
@Doodlesack I don't know if it's actually doing the same thing, but the icon and keyboard shortcut for "Synchronize" has been carried over to a new "Reload All from Disk" option, which sounds similar.Muntjac
This was the first answer that I saw, I wasn't able to do the file->synchronize because there was no such a button. After days of not being able to solve the issue i come back to here in desperate, and i noticed that there is a file-> repair ide button. I clicked to it, it reindexed, restarted etc. and I finally fixed it! I even tried to reset intellij, caches, maven.. I think name of the button might be changed from synchronize to repair ide.Cobby
@Tim's The "Synchronize" command was actually renamed "Reload All from Disk", but it's really the "Repair IDE" step that people should be using these days. I edited the answer to have people try that first.Muntjac
I
55

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

Isleen answered 17/2, 2015 at 7:51 Comment(1)
how to do in macSwank
S
35

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

Shivaree answered 24/7, 2012 at 14:0 Comment(5)
oddly enough, this actually caused a "red alert condition" for me that invalidating caches subsequently cleared.Loferski
where is "maven -> force reimport"? Where is the actual setting / option for this?Shaylyn
@StealthRabbi Right-click anywhere over the project structure, then Maven > Reimport...Cellar
Or you can also use Ctrl+Shift+A, type "Reimport" and choose either: "Reimport" or "Reimport All Maven Projects" (in doubt, reimport all).Cellar
In the Maven menu, this might now be called 'Reload All Maven Projects' (with a circular arrows icon)Kershner
C
12

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.

Christology answered 20/9, 2019 at 14:23 Comment(1)
I too tried everything and nothing worked. At last, I took backup of .idea folder --> deleted it --> reopen the project --> closed --> put the .idea back -> reopened. I think for me some cached files were not getting deleted earlier.Nereid
D
11

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.

Doti answered 6/8, 2018 at 7:31 Comment(3)
This is what was causing the issue for me. Getters and setters generated via annotation weren't being understood by IntelliJ. Thanks for the fix!Hight
Tried all the other solutions but none worked, excepting this one! ThanksHourigan
Thanks, in my case I updated IntelliJ updated but the plugin didn't update and wasn't compatible with the new version.Filefish
M
10

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 :)

Martelle answered 12/3, 2014 at 10:35 Comment(2)
I was going through all the low-hanging fruit trying to get the highlighting to work again and with your comment I realized that maybe OSX nuked my 1.6 JDK in an update... it did. And it moved Java out of /System/Library into /Library. Thanks for posting.Neogene
seems after the update to 1.7 and updating idea they fixed the problem. did not occure again.Martelle
W
8

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.

Wallacewallach answered 17/7, 2018 at 17:59 Comment(1)
This is the only thing that actually worked for me after updating IntelliJ. Thanks!Romany
N
7

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

Notum answered 29/5, 2018 at 9:46 Comment(0)
V
5

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.

Vins answered 10/10, 2014 at 3:54 Comment(0)
J
4

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)


Jimmiejimmy answered 8/5, 2021 at 7:47 Comment(1)
I like your preference-list of solutions here (I up-voted here). I referenced this in my Answer, and propose mine there to be [in-between] solution number 2. in your list here.Kershner
I
2

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.

Irreclaimable answered 26/6, 2013 at 23:46 Comment(1)
I have switched to the Maven 2 and then, return to the Maven 3. This steps apparently solved the problem for me.Airscrew
A
2

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.

Alfonso answered 9/11, 2017 at 20:58 Comment(0)
P
2

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!

Pedal answered 30/7, 2020 at 9:2 Comment(0)
C
2

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
Conduction answered 23/4, 2021 at 9:18 Comment(0)
V
1

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.

Verbenia answered 6/3, 2018 at 12:3 Comment(0)
B
1

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.

Boots answered 29/5, 2020 at 8:22 Comment(0)
P
1

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

Phrasal answered 17/7, 2020 at 0:22 Comment(0)
M
1

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

Marchland answered 25/7, 2020 at 2:42 Comment(0)
R
1

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

Ruelu answered 3/8, 2021 at 5:57 Comment(0)
K
1

[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

Kershner answered 19/5, 2022 at 22:55 Comment(0)
R
0

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.

Recurrent answered 14/6, 2016 at 13:13 Comment(0)
R
0

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

Risibility answered 9/8, 2016 at 13:1 Comment(0)
H
0

For me it was the JDK that was not set up correctly. I found a solution that I documented here: https://mcmap.net/q/56352/-intellij-idea-can-39-t-setup-jdk

Hamnet answered 19/10, 2016 at 9:51 Comment(0)
P
0

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.

Pacifa answered 25/9, 2017 at 23:14 Comment(0)
A
0

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

Anselme answered 23/2, 2018 at 23:53 Comment(0)
K
0

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!

Kanishakanji answered 2/3, 2018 at 15:54 Comment(0)
K
0

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.

Kelci answered 8/4, 2018 at 21:30 Comment(0)
S
0

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

When you start IntelliJ it will create the folder again.

Solenne answered 10/4, 2018 at 22:6 Comment(0)
D
0

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

Disgruntle answered 31/8, 2018 at 19:8 Comment(0)
T
0

Resolved by simply "Refresh All Gradle Projects"

Tiannatiara answered 11/2, 2019 at 12:2 Comment(0)
D
0

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.

Doodlesack answered 9/8, 2019 at 20:43 Comment(0)
C
0

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.

Culberson answered 14/7, 2020 at 11:36 Comment(0)
D
0

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.

Dispossess answered 11/8, 2021 at 12:21 Comment(0)
H
0

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

Henley answered 16/8, 2021 at 7:44 Comment(0)
K
0

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

Kershner answered 19/5, 2022 at 22:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.