gpt4 book ai didi

console - system.console NullPointerException

转载 作者:行者123 更新时间:2023-12-02 10:24:21 31 4
gpt4 key购买 nike

我知道这是一个新手错误,但我不知道如何修复它。

public static void main (String args[]){
Console kitty = System.console();
String username = kitty.readLine("Username: ");
}

String username = kitty.readLine("Username: ");

产生错误。有人可以告诉我我做错了什么吗,谢谢。

最佳答案

来自javadoc:

Returns the unique Console object associated with the current Java virtual machine, if any.

如果没有与 javadoc 关联的控制台,则指出的线是对空对象的方法的调用,因此会出现异常。

如何启动应用程序?

Whether a virtual machine has a console is dependent upon the underlying platform and also upon the manner in which the virtual machine is invoked. If the virtual machine is started from an interactive command line without redirecting the standard input and output streams then its console will exist and will typically be connected to the keyboard and display from which the virtual machine was launched. If the virtual machine is started automatically, for example by a background job scheduler, then it will typically not have a console.

关于console - system.console NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10963765/

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