title: Android error java.lang.NoSuchMethodError: android.view.MenuItem.getActionProvider
body: <p>I enabled the <code>ShareActionProvider</code> and I get this error:</p>
  
  <pre><code>java.lang.NoSuchMethodError: android.view.MenuItem.getActionProvider
  </code></pre>
  
  <p>But the way I use this class is like this:</p>
  
  <pre><code>    // SHARING ONLY ENABLED in SDK 14 which is Ice Cream Sandwich
      try
      {           
          if ( android.os.Build.VERSION.SDK_INT &gt;= 14 )
          {
              Button share = (Button)findViewById(R.id.share_button); 
              share.setOnClickListener(new Button.OnClickListener() 
              {  
                  public void onClick(View v) 
                  {                   
                      openOptionsMenu();
                  }
              });        
          }
          else
          {
              // HIDE THE TWO PAGE ELEMENTS
              Button share = (Button)findViewById(R.id.share_button); 
              TextView share_prompt = (TextView)findViewById(R.id.share_prompt); 
  
              share.setVisibility(View.GONE);
              share_prompt.setVisibility(View.GONE);              
          }
      }
      catch ( Exception e )
      {
  
      }
  </code></pre>
  
  <p>So I thought that I would not show the share button for earlier sdk's and I would be ok. But I am getting a lot of crashes.</p>
  
  <p>I can not really test this because I don't have a phone with an earlier version of the SDK. But does it mean that these pages crash for everyone who has the earlier SDK version? Or just people who click share?  How do I prevent this crashing?</p>
  
  <p>And I have these methods in the class. Should I just not run them if sdk is less than 14?</p>
  
  <pre><code>@Override
  public boolean onCreateOptionsMenu(Menu menu) 
  {
      getMenuInflater().inflate(R.layout.menu, menu);
      MenuItem item = menu.findItem(R.id.menu_item_share);
      myShareActionProvider = (ShareActionProvider)item.getActionProvider();
      myShareActionProvider.setShareHistoryFileName(
        ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME);
      myShareActionProvider.setShareIntent(createShareIntent());
      return true;
  }
  
  private Intent createShareIntent() 
  {
         Intent shareIntent = new Intent(Intent.ACTION_SEND);
         shareIntent.setType("text/plain");
         shareIntent.putExtra(Intent.EXTRA_TEXT, 
           "Some text");
         return shareIntent;
  }
  
  // Somewhere in the application.
  public void doShare(Intent shareIntent) 
  {
      // When you want to share set the share intent.
      myShareActionProvider.setShareIntent(shareIntent);
  }            
  </code></pre>
  
  <p>Thanks.
  Alex</p>