System.console()在NetBeans中提供NullPointerException

Max*_*its 4 java console netbeans exception nullpointerexception

我是Java的新手.

我有以下问题:方法readLine()或者nextLine(),nextInt()等抛出异常:NullPointerException.

我使用NetBeans IDE(如果重要的话).

public static void Reading()
{

    String qq;
    qq = System.console().readLine();
    System.console().printf(qq);
}
Run Code Online (Sandbox Code Playgroud)

aio*_*obe 12

某些IDE不提供控制台.请注意,在这些情况下System.console()返回null.

来自文件

返回:

     系统控制台(如果有),否则为null.

您可以随时使用System.in,System.out而不是如下:

String qq;
Scanner scanner = new Scanner(System.in);
qq = scanner.nextLine();
System.out.println(qq);
Run Code Online (Sandbox Code Playgroud)