System.console()在NetBeans中提供NullPointerException [英] System.console() gives NullPointerException in NetBeans
本文介绍了System.console()在NetBeans中提供NullPointerException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Java的新手。
我有以下问题:method readLine()
或 nextLine code>,
nextInt()
等引发异常: NullPointerException
。
我使用NetBeans IDE(如果有用)。
static void Reading()
{
String qq;
qq = System.console()。readLine();
System.console()。printf(qq);
}
解决方案
控制台。请注意, System.console()
在这些情况下会返回 null
。
返回:
<
System.in
和 System.out
代替,如下所示: 字符串qq;
扫描仪scanner =新扫描仪(System.in);
qq = scanner.nextLine();
System.out.println(qq);
I'm absolutely new in Java.
I have the following problem: method readLine()
or nextLine()
, nextInt()
etc. throw an exception: NullPointerException
.
I use NetBeans IDE(if it matters).
public static void Reading()
{
String qq;
qq = System.console().readLine();
System.console().printf(qq);
}
解决方案
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);
这篇关于System.console()在NetBeans中提供NullPointerException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文