Explain Codes LogoExplain Codes Logo

Intellij Cannot resolve symbol on import

java
intellij-settings
maven-vs-gradle
import-resolution
Anton ShumikhinbyAnton Shumikhin·Feb 24, 2025
TLDR

Battling the 'Cannot resolve symbol' error in IntelliJ? Invalidate caches and restart:

File > Invalidate Caches / Restart > Invalidate and Restart

For Maven aficionados, ensure dependencies are registered:

Maven Projects > Reimport All Maven Projects

For Gradle wizards:

Gradle > Refresh All Gradle Projects

Always double-check the Project SDK and libraries in the hydration circuit a.k.a. classpath:

Project Structure > SDKs and Project/Modules > Dependencies

It's surprising how often these checks resolve import mysteries.

Knock, knock! Who's there? Possible module mishaps

Ever busted a ghost in the machine? Check your project settings for phantom errors. Hit up:

File > Project Structure > Modules 

Ensure module source roots are correctly tagged as src or test. JVMTI error codes ain't Halloween fun, friend!

Maven vs. Gradle: Dawn of Nuances

Amidst the eternal war of Maven vs. Gradle, remember good old PEBCAK issues. Flummoxed? Generate sources, update folders:

Maven: Right-click on project > Maven > Generate Sources and Update Folders
Gradle: View > Tool Windows > Gradle > Your Project > Tasks > build > build (double-click)

Remember, misaligned compiler output paths are the silent ninjas of chaos.

Clash of the Classes: Conflict resolution

Ever met a class with an identity crisis? Look for class name doppelgängers or two-faced classes in different libraries. IntelliJ isn't akin to psychological warfare.

To err is to import: Sync checks

Paging Dr. Freeman, we have syntax errors in import teleport sequences. Define full package name. Test issue in a new project environment, it's almost like a parallel universe without the mess.

Exploring the Upside Down: Situational Analysis

Went through all the steps above and still facing the issue? Are you cursed? Probably not. Consider this: Maybe IntelliJ's version you are using was haunted by unpleasant bugs. Updating or downgrading may be the exorcism you need.

Running mvn idea:idea is your trusty Proton Pack against Import resolution spirits for projects managed with Maven.

Field trip to the FileSystem

Is the error playing hide and seek? May be the ghost of IntelliJ's internal state or filesystem antics. Try moving the project like one would with a Ouija board, or run a check on the file system.

Time for some Supernatural: Third-Party Troubles

Maybe the problem is the cursed talisman, a rogue plugin, or the library itself. Visualizing the decompiled classes can hint at whether the classes made it safely through the Bermuda triangle of the library packaging process.