It's giving null pointer exception. But the same code is generating the output when I run the program from command line.
Console c = System.console();
String s = c.read();
System.out.print(s);
It's giving null pointer exception. But the same code is generating the output when I run the program from command line.
Console c = System.console();
String s = c.read();
System.out.print(s);
The method System.console()
can return null, if no console device is present.
System.console()
null exception should be handled if your development required it, in case password reading etc.
Other alternate are available if you want to read input from command line.
Using Scanner class Or
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
String s=br.readLine();
System.console development
Reference: illegalargumentexception blog