What This Error Means
This error occurs when Java cannot find a class, method, or variable that is being used in the code. It is often caused by a missing import statement or incorrect class name.
Why It Happens
This error typically happens when a developer forgets to import a necessary class, tries to use a class or method that does not exist, or misspells a class name.
How to Fix It
- 1To fix this error, you need to import the required class at the beginning of the code. For the Scanner class, you need to import java.util.Scanner. Alternatively, you can use a wildcard import statement (import java.util.*;) if you are using other classes from the same package.
Example Code Solution
❌ Before (problematic code)
Java
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
}
}✅ After (fixed code)
Java
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
}
}Fix for Cannot find symbol: class Scanner on line 5
Browse Related Clusters
Related JAVA Errors
ORA-12545: TNS:Cannot register with TSLS (TNS Listener Service)
JAVAGuide
Error executing SQL query: Cannot insert explicit value for identity c
JAVAGuide
java.lang.StackOverflowError at com.example.Main.main(Main.java:15) -
JAVAGuide
Could not initialize Bean Validation provider for the constraint annot
JAVAGuide
Related JAVA Blog Articles
Have a different error? Get an instant explanation.
Explain Another Error