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

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-05 11:08:58

问题


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!");
    }
}

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

How can I fix this error?


回答1:


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



来源:https://stackoverflow.com/questions/63811584/why-does-my-first-hello-world-java-program-give-an-error-on-visual-studio-when-u

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!