JAVAWarningApril 18, 2026
Syntax Error
java: cannot find symbol symbol: class Scanner location: class Main
What This Error Means
This error occurs when the Java compiler cannot find a class, method, or variable that is used in the code. In this case, the compiler is unable to find the Scanner class, which is part of the java.util package.
Why It Happens
This error typically happens when a developer forgets to import the necessary classes or packages in the code. In this case, the Scanner class is not imported, causing the compiler to throw a syntax error.
How to Fix It
- 1To fix this error, you need to import the java.util.Scanner class at the beginning of the code. You can do this by adding the following line: import java.util.Scanner; Alternatively, you can use the fully qualified name of the class (java.util.Scanner) in the code.
Example Code Solution
❌ Before (problematic code)
Java
class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
}
}✅ After (fixed code)
Java
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
}
}Fix for java: cannot find symbol symbol: class Scanner location: class Main
Browse Related Clusters
Related JAVA Errors
Related JAVA Blog Articles
Have a different error? Get an instant explanation.
Explain Another Error