NullPointerException异常使用ShareActionProvider + actionbarsherlock [英] NullPointerException using ShareActionProvider + actionbarsherlock
本文介绍了NullPointerException异常使用ShareActionProvider + actionbarsherlock的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图用ShareActionProvider与actionbarsherlock,但我得到了:
I'm trying to use ShareActionProvider with actionbarsherlock, but i got:
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(菜单菜单)有关code是这样的:
The relevant code on onCreateOptionsMenu(Menu menu) is this:
@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有这样的:
and the menuhome.xml has this:
<item
android:id="@+id/share"
android:actionProviderClass="com.actionbarsherlock.widget.ShareActionProvider"
android:enabled="true"
android:showAsAction="ifRoom"
android:visible="true">
</item>
在哪里我错了?
推荐答案
固定...我需要调用之前则findItem夸大菜单
Fixed... I need to inflate the menu before calling findItem
这篇关于NullPointerException异常使用ShareActionProvider + actionbarsherlock的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文