JAVAWarningSyntax ErrorMay 9, 2026

Syntax Error

Cannot find symbol: class Scanner on line 5

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

  1. 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

Related JAVA Errors

Related JAVA Blog Articles

Have a different error? Get an instant explanation.

Explain Another Error