Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@override method does not override or implement a method from a supertype

Tags:

java

android

I'm having a small problem regarding my coding for android. I'm still very new to this and run into a small issue. No matter what I seem to do I cant seem to clear the error on my @override. The error is @override method does not override or implement a method from a supertype and the error is on all 3 of the last 3 @Override. Through that it comes up with an error for Menu, menu, MenuItem, itmsearch and KeyEvent saying cannot find symbol. Any help would be great and thank you in advance.

import android.os.Bundle;
import android.widget.ArrayAdapter;

public class MainActivity extends ListActivity
{


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    super.setTitle("My Films");

    setContentView(R.layout.main);

    setListAdapter(new ArrayAdapter<String>(this,
    R.layout.film_list_cell,
    R.id.text,
    CELLS));

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main_menu, menu);
    return true;
}
@Override
public boolean onOptionsItemsSelected(MenuItem item) {
    if (item.getItemId() ==R.id.itmsearch) {
    onSearchRequested();
    return true;
    }
    return false;
}
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if( keyCode == KeyEvent.KEYCODE_SEARCH) {
        onSearchRequested();
        return true;
    }
    return false;
}



static final String[] CELLS = 
        new String[] {"Cell 0", "Cell 1", "Cell 2",
            "Cell 3", "Cell 4", "Cell 5",
            "Cell 6", "Cell 7", "Cell 8", 
            "Cell 9", "CEll 10"};
        }
like image 384
Bcrscorpio Avatar asked Mar 25 '26 07:03

Bcrscorpio


1 Answers

Change onOptionsItemsSelected to onOptionsItemSelected.
................................................^

Here's the correct name of the method you want to override :

public boolean onOptionsItemSelected (MenuItem item)

EDIT:

Through that it comes up with an error for Menu, menu, MenuItem, itmsearch and KeyEvent saying cannot find symbol.

Make sure you import all the relevant classes :

import android.view.Menu;
import android.view.KeyEvent;
import android.view.MenuItem;
like image 117
Eran Avatar answered Mar 27 '26 20:03

Eran



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!