It:
Console c = System.console(); String readline; String u = c.readLine("%s", "args");
Returns a NullPointerException.However, the method signature:
NullPointerException.
public String readLine(String fmt, Object... args)
Why is this exception selected?
Console c = System.console();
Is cnull?
c
Doc :
public static console console ()Returns a unique console object associated with the current Java virtual machine, if any.Returns: System console, if any, otherwise null .
public static console console ()
Returns a unique console object associated with the current Java virtual machine, if any.
Returns: System console, if any, otherwise null .
NullPointerException is a RuntimeException, which means that it should not be declared in the method signature.
: http://www.codeguru.com/forum/showthread.php?t=487190
, , API , . , docs console() :
:
, . , , . , , ., System.console(). null. null.
, . , , . , , .
, System.console(). null. null.
java, , null.of null.
, Scanner IDE:
Scanner sc = new Scanner(System.in);
c null -?
, readLine c.readLine("args") - , ?
c.readLine("args")
System.console() null, , , , .
- . , "readline", .
Is it possible that in a program you somehow use this variable without initialization? (long shot, I know)
Because System.console()- nullin your IDE. Try instead java.util.Scanner:
System.console()
null
java.util.Scanner
import java.util.Scanner; Scanner s = new Scanner(System.in); String u = s.nextLine();