1

我正在尝试将 ShareActionProvider 与 actionbarsherlock 一起使用,但我得到了:

java.lang.NullPointerException
at com.iuculano.tvitaliane.Start.onCreateOptionsMenu(Start.java:387)
at com.actionbarsherlock.app.SherlockActivity.onCreatePanelMenu(SherlockActivity.java:167
at com.actionbarsherlock.ActionBarSherlock.callbackCreateOptionsMenu(ActionBarSherlock.java:542)

onCreateOptionsMenu(Menu menu) 上的相关代码是这样的:

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    // TODO Auto-generated method stub
    super.onCreateOptionsMenu(menu);
    MenuItem menuItem = menu.findItem(R.id.share);

    //MenuInflater blowUp = getSupportMenuInflater();
    //getSupportMenuInflater().inflate(R.menu.menuhome, menu);


    ShareActionProvider mShareActionProvider =  (ShareActionProvider) menuItem.getActionProvider();  //line 387

    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, getString(R.string.sharesubject));
    shareIntent.putExtra(Intent.EXTRA_SUBJECT,getString(R.string.sharetext));

    mShareActionProvider.setShareIntent(shareIntent);

menuhome.xml 有这个:

<item
    android:id="@+id/share"
    android:actionProviderClass="com.actionbarsherlock.widget.ShareActionProvider"
    android:enabled="true"
    android:showAsAction="ifRoom"
    android:visible="true">
</item>

我哪里错了?

4

1 回答 1

7

固定...我需要在调用 findItem 之前给菜单充气

于 2012-06-27T08:25:28.547 回答