I am trying to get the input from user by using System.console
. However, I get a NullPointerException
when I run the following code (I am trying to get input from the user).
import java.io.*;
public class Systemlearn {
public static void main(String[] args)throws IOException {
Console c=System.console();
System.out.println("Enter the Name:");
String str=c.readLine();
System.out.println(str);
}
}
Output:
Enter the Name:
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.io.Console.readLine()" because "c" is null
at week5.Systemlearn.main(Systemlearn.java:7)