Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NullPointerException in Console's readLine()

Tags:

java

console

This:

Console c = System.console();
        String readline;
        String u = c.readLine("%s", "args");

Throws a NullPointerException. Yet the signature of the method is:

 public String readLine(String fmt, Object... args)

Why's this exception being thrown?

like image 436
andandandand Avatar asked Dec 16 '09 22:12

andandandand


1 Answers

Console c = System.console();

Is c null?

Doc:

public static Console console()

Returns the unique Console object associated with the current Java virtual machine, if any.

Returns: The system console, if any, otherwise null.

like image 125
McDowell Avatar answered Oct 11 '22 14:10

McDowell