gpt4 book ai didi

Java 在 console.printf 上出错

转载 作者:行者123 更新时间:2023-12-02 03:05:16 25 4
gpt4 key购买 nike

我在 Netbeans 中输入了以下代码,但出现错误

package learn.java;

import java.io.Console;

public class LearnJava {
public static void main(String[] args) {
Console console = System.console();
console.printf("Hello My Name Is , Nitesh");
}
}

错误:

Exception in thread "main" java.lang.NullPointerException
at learn.java.LearnJava.main(LearnJava.java:8) C:\Users\The Alian\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 0 seconds)

最佳答案

您启用了控制台吗?请在此处查看说明:https://www.java.com/en/download/help/javaconsole.xml

如果做不到这一点,您可以用简单的替换控制台调用

System.out.println("Hello My Name Is , Nitesh");

或者对于格式化字符串:

String name = "Nitesh";
System.out.format("Hello My Name Is , %s", name);

关于Java 在 console.printf 上出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41844898/

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