Skip to content
Advertisement

I get an error which I can’t understand in java while getting a user input

import java.util.Scanner;
public class KK {

    public static void main(String[] args) {
    
        Scanner myObj = new Scanner(System.in);
        System.out.println("Enter username");

        String userName = myObj.nextLine();
        System.out.println("Username is: " + userName);

    }

}

This is the error I get

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 

    at ekdum.KK.main(KK.java:4)

Advertisement

Answer

This error normally occurs, if you use eclipse and your source file has errors. If there are any errors the java compiler from eclipse emits code, that throws an error. Try to clean and rebuild

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement