Skip to content

/errors/java/cannot-find-symbol

javac error: cannot find symbol

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash) · openjdk version "17.0.20.1" 2026-08-18updated
tool
Java
exit code
1
versions
Java 8+, Java 17, Java 21, Java 25
os
any

error: cannot find symbol means javac met an identifier (a class, variable or method name) that it cannot resolve in the current scope. The two lines under the error tell you which one: symbol: names the missing identifier and location: the class where javac looked. The usual fixes are a missing import, a typo or wrong case, a variable used outside its block, or a library missing from the class path.

Reproduce it

bash
cat > Main.java <<'EOF'
public class Main {
    public static void main(String[] args) {
        List<String> names = new ArrayList<>();
        names.add("ada");
        for (int i = 0; i < 1; i++) { int count = names.size(); }
        System.out.println(count);
    }
}
EOF
javac Main.java

Output · exit 1

Main.java:3: error: cannot find symbol
        List<String> names = new ArrayList<>();
        ^
  symbol:   class List
  location: class Main
Main.java:3: error: cannot find symbol
        List<String> names = new ArrayList<>();
                                 ^
  symbol:   class ArrayList
  location: class Main
Main.java:6: error: cannot find symbol
        System.out.println(count);
                           ^
  symbol:   variable count
  location: class Main
3 errors

javac reports one error per unresolved name: List and ArrayList (no import, symbol: class), and count (declared inside the loop, symbol: variable).

Fix: import and declare in scope

bash
cat > Main.java <<'EOF'
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        List<String> names = new ArrayList<>();
        names.add("ada");
        int count = 0;
        for (int i = 0; i < 1; i++) { count = names.size(); }
        System.out.println(count);
    }
}
EOF
javac Main.java && java Main

Output

1

Reading the symbol line

symbol: lineWhat to check
class XImport, spelling, case, or a JAR on the class path
variable xDeclaration and its scope (block, loop, try)
method m(int)Method name and parameter types on that class; static vs instance
location: package pA package that is not on the class path or was misspelled in the import

Sources