How to Fix IntelliJ Import Errors — Missing Classes and Packages
In this tutorial, you'll learn about How to Fix IntelliJ Import Errors. We cover key concepts, practical examples, and best practices.
The Problem
IntelliJ cannot resolve a class or package:
import com.example.MyClass; // Cannot resolve symbol 'MyClass'
Quick Fix
Step 1: Invalidate caches
File > Invalidate Caches and Restart > Invalidate and Restart
This clears the internal index and rebuilds from scratch.
Step 2: Reload the project
File > Reload All from Disk
Or rebuild the project:
Build > Rebuild Project
Step 3: Check module dependencies
File > Project Structure > Modules > Dependencies tab
Ensure the required library or module is added. Click + to add a dependency.
Step 4: Reimport Maven/Gradle dependencies
For Maven:
View > Tool Windows > Maven > Reload All Projects
For Gradle:
View > Tool Windows > Gradle > Reload All Gradle Projects
Step 5: Set the correct SDK
File > Project Structure > Project > Project SDK
Ensure the correct Java/ADK/Go SDK is selected.
Step 6: Check the module source root
Right-click the source folder > Mark Directory as > Sources Root.
Prevention
- Let Maven/Gradle sync complete before coding.
- Use
Ctrl+Shift+Aand type "Reload" for quick access. - Keep the
.idea/directory in version control for team consistency.
Common Mistakes with import error
- Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
- Using
returnto exit a function early instead of wrapping a pure value in the monad - Mixing let bindings with <- bindings in do notation, producing type errors
These mistakes appear frequently in real-world INTELLIJ code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro