Mark Williams
Mark Williams

Reputation: 1310

"Cannot resolve symbol" in Intellij IDEA

I am unable to use libraries from one "module" in another. I am seeing red class names and getting "Cannot resolve symbol ..." errors all over the place:

enter image description here

The other modules are referenced in File | Project Structure all the other module's Paths are correct and include the *.classes I'm trying to use:

enter image description here

I have also tried a File | Invalidate Caches but am still having the same problems.

What do I need to do to fix this?

Upvotes: 14

Views: 80914

Answers (8)

Dipesh Yadav
Dipesh Yadav

Reputation: 2857

Listed below are steps which may fix the problem:

1.Invalidate and refresh the IntelliJ's caches

File Menu -> Invalidate Caches / Restart -> Invalidate and restart

2.Project SDK selection

Check project settings from File Menu -> Project Structure Ensure an SDK is selected for the Project SDK. If is selected, click the 'New' button, select JDK and then select the correct path to the JDK e.g. /opt/java/jdk1.8 or c:\Java\Jdk1.8

3.Corrupt JDK

There may be a problem with your JDK installation, re-install JDK

4.Re-import the project

Close the project if it is open in IntelliJ Delete the .idea folder in the project source code folder. Start IntelliJ and Import the project.

You can choose any of them which will work for you.

Upvotes: 31

UchiTesting
UchiTesting

Reputation: 159

Just got this. Just went there. Invalidated the cache. Seemed to work until I wrote further lines. Then noticed that I was writing my code outside of the main() function. Moved the ending curly bracket further and voila.

Upvotes: 0

Sachidananda Naik
Sachidananda Naik

Reputation: 151

One more advise would be to make sure that you import the project properly. If it's a maven project, import pom.xml and if it's a gradle project, import gradle.build file to make sure that all the dependencies are downloaded correctly.

Upvotes: 0

Snehal Masne
Snehal Masne

Reputation: 3429

Run it from the project's root folder.

$ mvn -U idea:idea

Upvotes: 1

J.su
J.su

Reputation: 301

I faced a similar problem for no reason, I think it was caused by IDE(android studio). I have tried all of the above solutions but not worked. Finally, in my own situation, I solved this problem by the following actions:

  1. Delete your .idea folder in your local project.
  2. Reopen this project and just let Gradle run itself.

It was worked for me. I hope that my experience will be useful for you.

Upvotes: 6

dicle
dicle

Reputation: 1162

You can go to "File->Project Structure"

From "Project Settings", Select "Project" tab and there make sure that "Project SDK" has proper JDK selection.

enter image description here

Upvotes: 4

user8715994
user8715994

Reputation:

After you add dependencies to POM file, make it a habit to refresh POM by clicking on the 'Reimports maven projects' icon. Its the first icon in the maven tool window located to the right of the main intellij editor. Its a blue icon with 2 circular arrows. Clicking it ensures that the added dependencies are fully integrated into your project

Upvotes: 1

Alan
Alan

Reputation: 478

You need to add your external libraries/classes under dependencies in order for IDEA to see them when doing code analysis/autocomplete.

Upvotes: 4

Related Questions