Why does my first Hello World Java program give an error on Visual Studio when using System.out to print to screen?

huangapple go评论71阅读模式
英文:

Why does my first Hello World Java program give an error on Visual Studio when using System.out to print to screen?

问题

我在我的 Mac 笔记本电脑上使用 Visual Studio Code,我刚刚用 Java 写了我的第一个程序,但当我运行代码时,收到了关于 System.out 的错误信息。

public class Hello
{
    public static void main(final String[] args)
    {
        System.out.println("Hello, World!");
    }
}

"将对 System.out 或 System.err 的此使用替换为记录器。"

我该如何解决这个错误?

英文:

I'm using Visual Studio Code on my Mac laptop and I'm after writing my first program in Java but when I run the code I get an error message about System.out.

public class Hello
{
    public static void main(final String[] args)
    {
        System.out.println("Hello, World!");
    }
}

Why does my first Hello World Java program give an error on Visual Studio when using System.out to print to screen?

"Replace this use of System.out or System.err by a logger."

How can I fix this error?

答案1

得分: 2

这是一个 SonarLint 错误(Visual Studio Code 插件),而不是编译器错误。这个程序将会运行得非常好,但显然该插件被配置为在 IDE 中将此显示为错误(通常你不希望在生产代码中出现 System.out)。

根据 https://www.sonarlint.org/vscode/,你应该能够在你的 IDE 中调整规则:

> 在资源管理器中的 SonarLint 规则视图中,你可以激活和
> 停用规则以符合你的约定。每个问题上还有一个代码操作,可以快速停用对应的规则。

英文:

This is a sonarlint error (visual studio code plugin), not a compiler one. This program will run perfectly fine, but apparently the plugin is configured to display this as error in IDE (you usually don't want System.out in production code).

According to https://www.sonarlint.org/vscode/, you should be able to adjust the rules in your IDE:

> In the SonarLint Rules view in the explorer, you can activate and
> deactivate rules to match your conventions. There is also a code
> action on each issue to quickly deactivate the corresponding rule

huangapple
  • 本文由 发表于 2020年9月9日 20:21:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/63811584.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定