System.console()在NetBeans中给出NullPointerException [英] System.console() gives a NullPointerException in NetBeans
本文介绍了System.console()在NetBeans中给出NullPointerException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到以下问题:方法 readLine()
或 nextLine()
, nextInt()
等引发异常: NullPointerException
。
I have the following problem: method readLine()
or nextLine()
, nextInt()
, etc. throw an exception: NullPointerException
.
我使用 NetBeans IDE(如果有的话)。
I use the NetBeans IDE (if it matters).
public static void Reading()
{
String qq;
qq = System.console().readLine();
System.console().printf(qq);
}
推荐答案
某些IDE不提供一个控制台。请注意,在这种情况下, System.console()
返回 null
。
Some IDEs don't provide a console. Note that System.console()
returns null
in these cases.
来自文档阴离子
返回值:
Returns:
系统控制台(如果有),否则为null。
The system console, if any, otherwise null.
您始终可以使用 System.in
和 System.out
来代替,如下所示:
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);
这篇关于System.console()在NetBeans中给出NullPointerException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文