System.out not recognized

It drives me crazy. I have a package that works fine, then I renamed the package, and now I can not use System.out (or anything in the System class). For this, my Main class is worth it (I deleted EVERYTHING except the System.out line in case something else causes a problem).

 package goldminetosugarconvertor; public class Main { public static void main(String[] args) { System.out.println("prog init"); } } 

In NetBeans, out in System.out.println underlined with the error "cannot find symbol" , but it is strange that it shows the location as "class goldminetosugarconvertor.System ", which is clearly incorrect.

Any bright ideas? I assume that something broke when I renamed the package, but I just can’t understand that it will break so badly that the System not recognized.

+4
source share
2 answers

The goldminetosugarconvertor package must have a System class. When you changed that the old Main package was separate from this, you now shaded the System from java.lang to goldminetosugarconvertor.System .

If you do not remove this System class, you need to add System.out using java.lang. , i.e:

 java.lang.System.out.println("prog init"); 
+12
source

Today we had the same problem as the person who initially asked the question. Eclipse does not recognize System.out.println in my new class or any other that I created (except that it was in an older class in the same package), very strange!

I no longer have a (second) system class.

Restarting Eclipse did not help.

Rebooted my computer, did not help.

Fixed the problem by creating a new class called "String". I am surprised that Eclipse did not warn me! Anyway, I removed this new class and hey presto! I can print System.out.println in all my classes - no problem!

Hope this helps someone else too!

0
source

Source: https://habr.com/ru/post/1387670/


All Articles