gpt4 book ai didi

java - System.console() 在 NetBeans 中给出 NullPointerException

转载 作者:搜寻专家 更新时间:2023-11-01 01:12:45 25 4
gpt4 key购买 nike

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

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

public static void Reading()
{
String qq;
qq = System.console().readLine();
System.console().printf(qq);
}

最佳答案

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

来自 the documentanion

Returns:

     The system console, if any, otherwise null.

您始终可以使用 System.inSystem.out 代替,如下所示:

String qq;
Scanner scanner = new Scanner(System.in);
qq = scanner.nextLine();
System.out.println(qq);

关于java - System.console() 在 NetBeans 中给出 NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26078106/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com