Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intellij Cannot resolve symbol on import

People also ask

How do I fix resolve Cannot resolve symbol in IntelliJ?

First of all you should try File | Invalidate Caches and if it doesn't help, delete IDEA system directory. Then re-import the Maven project and see if it helps.

Do not import * IntelliJ?

To avoid IntelliJ IDEA replacing imports with * , you need to configure the Class count to use import with '*' and Names count to use static import with '*' preferences: Go to Preferences > Editor > Code Style > Java.


You can try invalidating the cache and restarting IntelliJ, in many cases it will help.

File -> Invalidate Caches/Restart


There can be multiple reasons for this. In my case it was wrong source root issue. Invalidate caches didn't work along with other solutions.

Check your module source roots.

  1. Project Structure (Ctrl+Alt+Shift+S).

  2. Modules

  3. Select your problem module.

  4. Change tab on top of window "Sources".

  5. Remove unwanted source roots. Keep one and add src and test source roots in this root.


File -> Invalidate Caches/Restart And Build your project


IntelliJ has issues in resolving the dependencies. Try the following:

  1. Right click on pom.xml -> Maven -> Reimport
  2. Again Right click on pom.xml -> Maven -> Generate sources and update folders

Run this command in your project console:

mvn idea:idea

Done. Had this issue many times. Tried 'Invalidate Cache & Restart' and all other solutions. Running that command works perfect to me. I'm currently using IntelliJ 2019.2, but this also happened in previous versions and solution worked as well.


Check your module dependencies.

  1. Project Structure (Ctrl+Alt+Shift+S).
  2. Modules
  3. Select your problem module.
  4. Change tab on top of window "Dependencies".
  5. Check what needed library (maybe, you need to add specified library in the tab 'libraries') or module has listed here and it has right scope ('complile' mostly).