views:

7403

answers:

7

Anytime I have to re-import my projects into Eclipse (if I reinstalled Eclipse, or changed the location of the projects), almost all of my overridden methods are not formatted correctly, causing the error 'The method ?????????? must override a superclass method'.

It may be noteworthy to mention this is with Android projects - for whatever reason, the method argument values are not always populated, so I have to manually populate them myself. For instance:

list.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {

      public void onCreateContextMenu(ContextMenu menu, View v,
        ContextMenuInfo menuInfo) {
       //These arguments have their correct names
      }


     });

will be initially populated like this:

list.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {

      public void onCreateContextMenu(ContextMenu arg1, View arg2,
        ContextMenuInfo arg3) {
       //This methods arguments were not automatically provided
      }


     });

The odd thing is, if I remove my code, and have Eclipse automatically recreate the method, it uses the same argument names I already had, so I don't really know where the problem is, other then it auto-formatting the method for me.

This becomes quite a pain having to manually recreate ALL my overridden methods by hand. If anyone can explain why this happens or how to fix it .. I would be very happy.

Maybe it is due to the way I am formatting the methods, which are inside an argument of another method?

+38  A: 

Eclipse is defaulting to Java 1.5 and you have classes implementing interface methods (which in Java 1.6 can be annotated with @Override, but in Java 1.5 can only be applied to methods overriding a superclass method).

Go to your project/ide preferences and set the java compiler level to 1.6 and also make sure you select JRE 1.6 to execute your program from eclipse.

Thank you so much, never would have figured that out!
Tim H
Happy to help. Been bitten by the same myself ;)
+1 for short and clear answer.
OemerA
A: 

Thanks so much for this!

Y.Z
A: 

I wanted to thank you for this answer too - I had everything set to Java 6 in my project and completely forgot my IDE java settings, and sure enough it was set to Java 5. I simply went into Window --> Preferences --> Java --> Compiler and changed the Java compliance level to 6.0 and everything worked. Again thanks!!

Margaret
A: 

Thank you very much.It really helped me.

Raja
A: 

Hi alphazero,

Im newbie in java/eclpise. Can u help me? my problem is @override method is work perfectly at java version 1.6, but i want it works too at java version 1.5 because it will integrating with 1.5 application.

Do you know how to fix this problem with @override in 1.5 version? what must i do?

Thanks in advance.

rezinprince
1) write your own question; 2) if it comes to the worst, just comment out (or remove) @override
afriza
As far as I know, you comment it out.
+2  A: 

With Eclipse Galileo you go to Eclipse -> Preferences menu item, then select Java and Compiler in the dialog.

Now it still may show compiler compliance level at 1.6, yet you still see this problem. So now select the link "Configure Project Specific Settings..." and in there you'll see the project is set to 1.5, now change this to 1.6. You'll need to do this for all affected projects.

This byzantine menu / dialog interface is typical of Eclipse's poor UI design.

Paul
+1 - this was driving me crazy.
I82Much
A: 

Thank you very much. It resolved my problem very quickly.

anony