title: Exception: This is not supported, use MenuItemCompat.getActionProvider()
body: <p>I'm trying to make "Share" button in Action Bar of Android Application.
  Here my code:</p>
  
  <pre><code>import android.content.Intent;
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.support.v7.app.ActionBarActivity;
  import android.view.LayoutInflater;
  import android.view.Menu;
  import android.view.MenuInflater;
  import android.view.MenuItem;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ShareActionProvider;
  import android.widget.TextView;
  </code></pre>
  
  <p>and fragment part:</p>
  
  <pre><code>{
  private String mForecastText;
  
  public PlaceholderFragment() {
      setHasOptionsMenu(true);
  }
  
  private Intent sharedIntentMaker(){
      Intent shareIntent = new Intent(Intent.ACTION_SEND);
      shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
      shareIntent.setType("text/plain");
      shareIntent.putExtra(Intent.EXTRA_TEXT, mForecastText + "#SunshineApp");
      return shareIntent;
  }
  @Override
  public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
      inflater.inflate(R.menu.menu_detail, menu);
      MenuItem menuItem = menu.findItem(R.id.menu_action_share);
      ShareActionProvider mShareActionProvider = (ShareActionProvider) menuItem.getActionProvider();
      mShareActionProvider.setShareIntent(sharedIntentMaker());
  
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      View rootView = inflater.inflate(R.layout.fragment_detail, container, false);
  
      TextView textIntent = (TextView) rootView.findViewById(R.id.textIntent);
      Intent intent = getActivity().getIntent();
      mForecastText = intent.getStringExtra("INT_PS");
      textIntent.setText(mForecastText);
      return rootView;
  }
  </code></pre>
  
  <p>When I run my app on emulator or even real device, I get exception:</p>
  
  <pre><code>AndroidRuntime﹕ FATAL EXCEPTION: main java.lang.UnsupportedOperationException: This is not supported, use MenuItemCompat.getActionProvider()
  </code></pre>
  
  <p>and it links to onCreateOptionsMenu()'s strings:</p>
  
  <pre><code>ShareActionProvider mShareActionProvider = (ShareActionProvider) menuItem.getActionProvider();
  mShareActionProvider.setShareIntent(sharedIntentMaker());
  </code></pre>
  
  <p>What I'm doing wrong?</p>
  
  <p>P.S.: Stacktrace of error from logcat:</p>
  
  <blockquote>
    <p>01-11 13:03:17.490    2331-2331/com.*****.*****.***** E/AndroidRuntime﹕ FATAL EXCEPTION: main
        Process: com.*****.*****.*****, PID: 2331</p>
  </blockquote>
  
  <pre><code>java.lang.UnsupportedOperationException: This is not supported, use MenuItemCompat.getActionProvider()
  
          at android.support.v7.internal.view.menu.MenuItemImpl.getActionProvider(MenuItemImpl.java:645)
          at com.project.malina.sunsine.DetailActivity$PlaceholderFragment.onCreateOptionsMenu(DetailActivity.java:70)
          at android.support.v4.app.Fragment.performCreateOptionsMenu(Fragment.java:1868)
          at android.support.v4.app.FragmentManagerImpl.dispatchCreateOptionsMenu(FragmentManager.java:1989)
          at android.support.v4.app.FragmentActivity.onCreatePanelMenu(FragmentActivity.java:276)
          at android.support.v7.app.ActionBarActivity.superOnCreatePanelMenu(ActionBarActivity.java:276)
          at android.support.v7.app.ActionBarActivityDelegate$1.onCreatePanelMenu(ActionBarActivityDelegate.java:79)
          at android.support.v7.app.ActionBarActivityDelegateBase.preparePanel(ActionBarActivityDelegateBase.java:979)
          at android.support.v7.app.ActionBarActivityDelegateBase.doInvalidatePanelMenu(ActionBarActivityDelegateBase.java:1182)
          at android.support.v7.app.ActionBarActivityDelegateBase.access$100(ActionBarActivityDelegateBase.java:79)
          at android.support.v7.app.ActionBarActivityDelegateBase$1.run(ActionBarActivityDelegateBase.java:115)
          at android.os.Handler.handleCallback(Handler.java:739)
          at android.os.Handler.dispatchMessage(Handler.java:95)
          at android.os.Looper.loop(Looper.java:135)
          at android.app.ActivityThread.main(ActivityThread.java:5221)
          at java.lang.reflect.Method.invoke(Native Method)
          at java.lang.reflect.Method.invoke(Method.java:372)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) 
  </code></pre>