Genadinik
Genadinik

Reputation: 18639

Android - error: cannot override the final method in SherlockActivity

I am getting this error when adding this method to my class:

  @Override
  public boolean onCreateOptionsMenu(Menu menu) 
  {
      // Inflate your menu.     
      getSupportMenuInflater().inflate(R.menu.share_action_provider, menu);

      // Set file with share history to the provider and set the share intent.
      MenuItem actionItem = menu.findItem(R.id.menu_item_share_action_provider_action_bar);
      ShareActionProvider actionProvider = (ShareActionProvider) actionItem.getActionProvider();        

      //actionProvider.setShareHistoryFileName(ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME);
      // Note that you can set/change the intent any time,
      // say when the user has selected an image.
      actionProvider.setShareIntent(createShareIntent());

      return true;
  }   

Here is how I declare the class:

public class MainActivity extends SherlockActivity implements ActionBar.OnNavigationListener  

and I have this method in other projects and I dont' get that error. Would anyone know why this error started happening here?

Thanks!

Upvotes: 2

Views: 2448

Answers (2)

Marcos Vasconcelos
Marcos Vasconcelos

Reputation: 18276

SherlockActivity does override that methods as final so the framework can handle itself.

To fix this, only delete the imports from Menu, MenuItems and etc.. and import from com.sherlockbar since you are overriding the correct method.

Upvotes: 9

Bryan Herbst
Bryan Herbst

Reputation: 67229

You are likely using the wrong Menu class.

SherlockActivity overrides and finalizes the Android-standard onCreateOptionsMenu(android.view.Menu menu) method.

It also declares the (new, overloaded) method onCreateOptionsMenu(Menu menu), which takes a com.actionbarsherlock.view.Menu.

Upvotes: 2

Related Questions