Organizational Research By

Surprising Reserch Topic

why menuitemcompat getactionprovider returns null using -'java,android'

why menuitemcompat getactionprovider returns null  using -'java,android'

I tried to use on actionbar in my app. So I followed the example from android document but got some issues.
Here's my menu xml:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android=""
    xmlns:myapp="" >

        myapp:actionProviderClass="" />


here's my code to create the share action button:

public void onCreateOptionsMenu (Menu menu, MenuInflater inflater) {
    inflater.inflate(, menu);
    MenuItem shareItem = menu.findItem(;
    ShareActionProvider mShareActionProvider = (ShareActionProvider)MenuItemCompat.getActionProvider(shareItem);
    super.onCreateOptionsMenu(menu, inflater);

My question is:

MenuItemCompat.getActionProvider(shareItem) always returns null for me, why's that?
When I comment those lines, the share button appears on the bar but does nothing while clicking, how to fix it(if question 1 can't be solved)?

btw, I checked codes of MenuItemCompat.getActionProvider, it looks like this method will check if the menu item implements SupportMenuItem interface and returns fail if it isn't. How could I deal with it?

asked Sep 7, 2015 by rajesh
0 votes

Related Hot Questions

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.