4

This is driving me absolutely crazy. I have a package that was working fine, then I renamed the package and now I cannot use System.out (or anything in the System class). For what it's worth here is my Main class (I've removed EVERYTHING except the System.out line just in case something else was causing the issue).

package goldminetosugarconvertor;

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

In NetBeans the out in System.out.println is underlined with an error "cannot find symbol" but the weird thing is it shows the location as "class goldminetosugarconvertor.System" which is obviously wrong.

Any bright ideas? I am guessing that something got broken when I renamed the package but I just can't figure out what would break so bad that System was not recognised.

Kai
  • 38,985
  • 14
  • 88
  • 103
takesides
  • 127
  • 1
  • 1
  • 10

2 Answers2

12

You must have a System class in the package goldminetosugarconvertor. When you changed whatever the old package Main was apart of to this one, you've now shadowed System from java.lang with goldminetosugarconvertor.System.

Unless you remove this System class, you'll have to prepend System.out with java.lang., ie:

java.lang.System.out.println("prog init");
AusCBloke
  • 18,014
  • 6
  • 40
  • 44
  • YES!! That was it! Thanks for the swift response everyone. lack of sleep strikes again :) – takesides Dec 23 '11 at 02:54
  • 2
    @takesides: If I were you, I'd probably avoid naming my classes the same as the ones in the Java library, or at least common ones like `System`. – AusCBloke Dec 23 '11 at 02:56
  • Don't forget to accept AusCBloke's answer. He nailed this one for you :) – rfeak Dec 23 '11 at 03:36
0

Had the same problem today as the person that originally posed the question. Eclipse would not recognize System.out.println in my new class or any other that I created (except it would in an older class in the same package), very strange!

Didn't already have a (second) System class.

Restarted Eclipse, didn't help.

Restarted my PC, didn't help.

Fixed the problem by creating a new class called 'String' .. I'm surprised that Eclipse didn't warn me! Anyway I deleted that new class and hey presto ! I can type System.out.println in all my classes - no problem!

Hope this helps someone else too !