/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
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.javaOutput · 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 errorsjavac 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
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 MainOutput
1
Reading the symbol line
| symbol: line | What to check |
|---|---|
| class X | Import, spelling, case, or a JAR on the class path |
| variable x | Declaration and its scope (block, loop, try) |
| method m(int) | Method name and parameter types on that class; static vs instance |
| location: package p | A package that is not on the class path or was misspelled in the import |
Sources
Related pages
errors · javaError: Could not find or load main classJava cannot find the class you asked it to run: a package class run by its short name, or a wrong -cp. Use the fully qualified name from the root. Real output.errors · javajava.lang.NullPointerException: Cannot invoke "String.length()" because "name" is nullJava's helpful NullPointerException names the call that failed and the null variable. Why it can say <local1> instead of a name, and how to fix the null.errors · csharpC# error CS0246: The type or namespace name could not be foundCS0246 means the C# compiler cannot resolve a type or namespace: a missing using directive, NuGet package or project reference. Real dotnet build output.