Issue
I have the following problem: method readLine()
or nextLine()
, nextInt()
, etc. throw an exception: NullPointerException
.
I use the NetBeans IDE (if it matters).
public static void Reading()
{
String qq;
qq = System.console().readLine();
System.console().printf(qq);
}
Solution
Some IDEs don't provide a console. Note that System.console()
returns null
in these cases.
From the documentanion
Returns:
The system console, if any, otherwise null.
You can always use System.in
and System.out
instead, as follows:
String qq;
Scanner scanner = new Scanner(System.in);
qq = scanner.nextLine();
System.out.println(qq);
Answered By - aioobe