Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Unresolved compilation problem: scanner cannot be resolved. How do I solve this problem?

When running this code;

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("Welcome to Bank of America");
        System.out.println("Input your name;");
        String name = scanner.nextLine();
        System.out.println("Hello there "+name);
    }
}

I receive the following error message;

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    scanner cannot be resolved

    at Main.main(Main.java:7)

I’ve already searched online for solutions, and none of them work for me. Most of them show examples where a ´;´ is missing, or it wasn’t imported, or that the JDK was out of date. I’ve already imported java.util.Scanner, my JDK and version of Eclipse are up to date, I mean I installed them all 5 hours ago, I don’t understand what the problem is or how to begin resolving it. I’m working with the Eclipse IDE 2023-03 and jdk-20.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The Scanner reference is named input (not scanner). Change

String name = scanner.nextLine();

to

String name = input.nextLine();

Or, change

Scanner input = new Scanner(System.in);

to

Scanner scanner = new Scanner(System.in);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading