• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Cant override onOptionsItemSelected

D

Deleted User

Guest
5voc29.png


"The method onOptionsItemSelected(MenuItem) of type ActivityLogin must override a superclass method"


Why is this happening? It had no problem letting me override onCreateOptionsMenu. Also, if you look closely, you'll notice that it doesn't care about me typing super.onOptionsItemSelected(item);.

What gives?
 
That is not true at all.

@Override tells the compiler to override the original method and use yours instead
.

No it doesn't.

Any non-final method of a non-final class can be overridden in a derived class, and the compiler doesn't need any annotations to make that happen.

If you believe that it's not possible to override a method without using @Override, then how come I've been doing it for about 13 years, and only started to use annotations relatively recently? :)

And how come when I've had the same error message about @Override, I've just removed the annotation and everything worked just fine?

There are times when you can't achieve what you want without annotations. (Such as using the web services functionality that comes with Java 6). But this isn't one of those times.

Mark
 
Upvote 0
Remove the import you added and your current override of onOptionsItemSelected.

Then have Eclipse add the overridden method to your Activity subclass for you by going into the Source menu, choosing Override/Implement Methods, selecting onOptionsItemSelected(MenuItem) under Activity, and then finally clicking OK.

Eclipse will add a new override to your class with exactly the right imports and the right spelling.
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones