Often when importing Android code into my Eclipse workspace, I find that there are a lot of new ‘errors’ introduced to the code. These errors were closely linked to my overriden classes (something you’ll find quite often in android code) and read “The method X must override a superclass method” . For the longest time I’ve wondered how to reliably fix those bugs (until now I had been removing and re-adding the @Override keyword as appropriate to make the compiler shut up). This morning I stumbled across a Stack Overflow thread that finally solves this problem.
You see, the problem is related to which version of Java the code is checked for compatibility errors against. Eclipse defaults to using Java 1.5, which only allows the use of interface methods if super() is called. Java 1.6 allowed the use of the @Override keyword to designation the interface implementation which is current standard way of overriding interface classes in Android coding.
To fix your problem you just need to do a bit of tinkering in the project settings in Eclipse. Go to your project preferences and under Java > Compiler set the java compiler to 1.6. While this might fix the error, it is more likely that you’re going to have to change the project specific value for compiler level as well. Select ”Configure project specific settings” and change the java compiler value there to 1.6 as well. After an automatic rebuild of your project, you should see all of those pesky error messages disappear!
