IntelliJ
Java
error handling
cannot find symbol
debugging

Fix "cannot find symbol" in a Java project in IntelliJ

Codemia Knowledge Hub ·

"Cannot find symbol" is a javac compilation error: the compiler met a name (a class, method, variable or field) that it cannot resolve in the current context. In IntelliJ the cause is usually a typo, a missing import, a stale classpath, a visibility problem, or outdated compiled classes. If the code looks correct, start with Build > Rebuild Project.

Common causes

  1. Misspelled identifiers. Java is case-sensitive, so student and Student are different names.
  2. Missing or wrong imports. A class that is not imported, or imported from the wrong package, is not recognized.
  3. Incorrect classpath. If you recently moved a library or changed the project structure, IntelliJ may still point at the old classpath configuration.
  4. Visibility. Accessing private members from outside the class, or package-private members from another package, triggers the error.
  5. Outdated compilation. IntelliJ may be using stale compiled classes because the project was not cleaned properly.

Example: a typo in the class name

java
1public class Example {
2    public static void main(String[] args) {
3        Student student = new Student();
4    }
5}
6
7class Stundent {
8    // Class definition
9}

Compiling this gives "cannot find symbol" because the class is declared as Stundent, not Student. The compiler looks for Student and finds nothing by that name.

How to fix it

  • Check spelling and case of every identifier involved.
  • Fix imports. Press Alt+Enter on an unrecognized symbol to let IntelliJ auto-import the class.
  • Rebuild the project with Build > Rebuild Project to regenerate class files from scratch.
  • Check the classpath under File > Project Structure > Modules > Dependencies and make sure the needed libraries are listed.
  • Adjust visibility so the element is accessible where it is used, or move the call into scope.

Preventing it in IntelliJ

  • Keep code inspection and auto-completion on. IntelliJ flags unresolved symbols in real time and often suggests a fix.
  • Rename with IntelliJ's refactoring tools so names change consistently across the project.
  • Commit regularly. The git log helps you find when the error was introduced.
CauseDescriptionResolution
Misspelled IdentifiersTypographical errors causing reference mismatchCheck spelling and correct typos
Unsatisfied ImportsMissing or incorrect importsEnsure proper imports
Incorrect ClasspathMisconfigured classpath settingsUpdate/reconfigure project classpath
Incorrect VisibilityInaccessible variables/methods due to scopeAdjust visibility or access scope
Outdated CompilationIntelliJ using stale compiled classesClean and rebuild project

Course
Intermediate
27 lessons
14 hours
OOD Fundamentals

Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.

View the course
Data 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.

Practice algorithms