IntelliJ "Cannot resolve symbol" on import: how to fix it
Codemia Knowledge Hub ·
IntelliJ IDEA shows "Cannot resolve symbol" when it cannot find the definition of a class or package you reference, often on an import line. The usual causes are a dependency missing from the build configuration, a wrong or missing project SDK, corrupted caches, an excluded module or source folder, or a typo in the import.
1. The dependency is not configured
The library you import is not set up correctly in your build system (Maven or Gradle).
- Maven: Make sure
pom.xmllists the correct dependencies. After editing it, right-clickpom.xmlin IntelliJ and select "Maven" -> "Reload". - Gradle: Check that
build.gradleincludes the dependencies you need, then click "Reload All Gradle Projects" in IntelliJ.
2. The project SDK is wrong or missing
Go to "File" -> "Project Structure" -> "Project" and make sure the correct SDK is selected. If it is not listed, add it with "New".
3. Caches or indexes are corrupted
Go to "File" -> "Invalidate Caches / Restart..." and choose "Invalidate and Restart" to clear the caches and restart the IDE.
4. Sources or modules are excluded
Sources or modules can be accidentally marked as excluded.
- Open "File" -> "Project Structure" -> "Modules" and check that module paths are correct and not marked as "Excluded".
- In the "Sources" tab of the module settings, verify the source directories and dependencies.
5. The import statement is wrong
Check the spelling of the import, and make sure you import the class from the correct package and version.
Example: StringUtils from Apache Commons Lang
Say your project uses Apache Commons Lang:
If StringUtils shows "Cannot resolve symbol", work through these steps.
First, check that commons-lang3 is in your pom.xml:
Then:
- Reload the Maven project so the dependency is imported.
- Check the project SDK in Project Structure.
- If the error remains, invalidate the caches and restart IntelliJ.
Causes and fixes at a glance
| Issue/Scenario | Cause | Solution |
| Dependency not resolved | Dependency not in build file | Add to pom.xml or build.gradle and reload the project |
| SDK issues | SDK path incorrect or absent | Set correct SDK in "Project Structure" |
| Cache corruption | Project indices are corrupted | Use "Invalidate Caches / Restart" |
| Module not recognized | Module path is incorrect/excluded | Ensure correct module path and check module settings |
| Wrong import statement | Typo in import statement | Correct the statement or ensure correct version/package is being referenced |
Related reading
- IntelliJ does not show 'Class' when we right click and select 'New
- IntelliJ does not terminate Spring Boot applications build with gradle
- IntelliJ Errorjava error release version 5 not supported
- intellij idea - Error java invalid source release 1.9
- Intellij IDEA complains cannot resolve spring boot properties but they work fine
- Intellij IDEA Java classes not auto compiling on save
- Intellij IDEA, format all code in a project
- IntelliJ IDEA generating serialVersionUID

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseData Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.