IntelliJ "Cannot find declaration to go to" fixes
Codemia Knowledge Hub ·
When IntelliJ IDEA (or Android Studio) says it cannot find a declaration to go to, its index of the project is usually corrupted or out of date, or the project's SDK, modules or build-tool dependencies are misconfigured. Start with File > Invalidate Caches / Restart, then check the SDK and reimport Maven or Gradle.
Symptoms
- Unresolved symbols: variables or methods are highlighted as unresolved even though they are declared correctly.
- Broken navigation:
Ctrl + Clickand similar features cannot jump to declarations. - False errors: linting warnings and false-positive compilation failures appear.
Indexing and caching
IntelliJ builds indexes that map symbols to their declarations, and code completion, navigation and refactoring depend on them.
- Index corruption: indexes can become corrupted or outdated, leaving references unresolved.
- Memory limits: large projects can exhaust memory and stop IntelliJ from keeping indexes accurate.
Project configuration
- Wrong SDK: an inappropriate SDK version can stop symbols from being recognized.
- Misconfigured modules and libraries: missing or incorrect library paths prevent resolution.
- Unrecognized file types: files with extensions IntelliJ does not recognize may not be indexed.
Dependency management
- Build tool problems: errors in Maven, Gradle or SBT setup break dependency resolution.
- Missing or broken
pom.xmlorbuild.gradle: IntelliJ cannot import dependencies without a correct build file.
Fixes
Rebuild the indexes
- Invalidate caches: go to
File > Invalidate Caches / Restart. - Rebuild indexes: this clears the existing indexes and restarts indexing.
Check the project structure
- SDK: verify it under
Project Structure > Project. - Module dependencies: review
Project Structure > Modules.
Sync dependencies
- Sync build scripts: run
Maven > ReimportorGradle > Refresh. - Review build files: make sure
pom.xml,build.gradleor other build scripts are correct.
Check file types
- File associations: verify them under
Settings > Editor > File Types.
Other measures
- More memory: edit
idea.vmoptionsto give IntelliJ more memory. - Update IntelliJ: newer versions include bug fixes and improved indexing.
- Custom scripts: for large projects, scripts can simplify build and indexing.
| Aspect | Description |
| Indexing & Caching | Core mechanism responsible for identifying declarations. |
| Configuration Issues | SDK and module setup errors lead to unresolved symbols. |
| Dependency Management | Misconfigured dependencies impede symbol resolution. |
| Reindexing Fixes | Often resolves issues by clearing and rebuilding indexes. |
| Increasing Memory | Essential for large projects laden with symbols. |
| Maintaining IDE Updates | Reduces errors through regular updates and bug fixes. |
Related reading
- Intellij Cannot resolve symbol on import
- IntelliJ does not show 'Class' when we right click and select 'New
- IntelliJ Errorjava error release version 5 not supported
- Intellij IDEA complains cannot resolve spring boot properties but they work fine
- Intellij IDEA Java classes not auto compiling on save
- intellij incorrectly saying no beans of type found for autowired repository
- IntelliJ Initialization failed for ''https//start.spring.io'' Please check URL, network and proxy settings
- IntelliJ inspection gives Cannot resolve symbol but still compiles code
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseNo course covers this one yet
Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.
Build my courseInterview Questions practice on Codemia
Over 11,000 interview practice questions for 300+ companies, searchable by company and role.