Reputation: 4821
I have a problem with this on Eclipse
OnItemClickListener onClick = new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getApplicationContext(), adapter.getItem(position), Toast.LENGTH_LONG);
Log.i("ITEM CLICK", adapter.getItem(position));
}
};
Eclipse is telling me that onItemClick must override a superclass method... and i Have to remove @Override annotation. But it's overriding a method... or isn't it?
Thanks
Upvotes: 1
Views: 1256
Reputation: 87
Using the @Override annotation on methods that implement those declared by an interface is only valid from Java 6 onward. It's an error in Java 5.
Make sure that your IDE projects are setup to use a Java 6 JRE, and that the "source compatibility" is set to 1.6 or greater. Open the Window > Preferences dialog, and browse to Java > Compiler. There you can set the "Compiler compliance level" to 1.6.
Remember that Eclipse can override these global settings for a specific project, so check those too.
Upvotes: 0
Reputation: 4705
May be you imported the wrong OnItemClickListener. If the methods's signature differs the compiler recognizes that it cannot possibly be an override.
Upvotes: 1
Reputation: 17087
In Java 1.5 @Override on the implementation of an interface method is considered incorrect. In Java 1.6 otoh, @Override on interface implementations is completely valid.
If you switch your compiler compliance level to 1.6 in Eclipse you'll be allowed to sprinkle your interface implementations with all the @Overrides you want.
Project properties -> Java Compiler & alter the "Compiler compliance level" to 1.6.
Upvotes: 2
Reputation: 66657
I am assuming you are using java 1.5 as compilance level that is why you are seeing the error. If you want to avoid these warnings you may change compilance level to 1.6. Here is SO discussion on this topic. Eclipse override error
If you want to use 1.5 compilance level only, you can safely remove override.
Upvotes: 1