我在实现 ShareActionProvider ActionBarSherlock 时遇到问题。Ja把所有的compenentes,但是当我编译NullPointException的代码。以下错误:
08-08 23:06:22.315: E/AndroidRuntime(2286): 致命异常: main 08-08 23:06:22.315: E/AndroidRuntime(2286): java.lang.ClassCastException: com.actionbarsherlock.widget.ShareActionProvider 不能被转换为 android.view.ActionProvider 08-08 23:06:22.315: E/AndroidRuntime(2286): at android.view.MenuInflater$MenuState.readItem(MenuInflater.java:359) 08-08 23:06:22.315: E/AndroidRuntime(2286): 在 android.view.MenuInflater.parseMenu(MenuInflater.java:145) 08-08 23:06:22.315: E/AndroidRuntime(2286): 在 android.view.MenuInflater.inflate(MenuInflater.java :95) 08-08 23:06:22.315: E/AndroidRuntime(2286): 在 br.ftsys.churrascalc.MainActivity.onCreateOptionsMenu(MainActivity.java:136)
我的 xml 文件位于 res/menu/main 中:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/share"
android:orderInCategory="100"
android:title="@string/share"
android:showAsAction="ifRoom"
android:actionProviderClass="com.actionbarsherlock.widget.ShareActionProvider"/>
Minha 主要活动:
public class MainActivity extends SherlockActivity{
private ShareActionProvider mShareActionProvider;
.
.
.
.
@Override
public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {
getSupportMenuInflater().inflate(R.menu.main, menu);
mShareActionProvider = (ShareActionProvider) menu.findItem(R.id.share).getActionProvider();
/** Getting the target intent */
Intent intent = getDefaultShareIntent();
/** Setting a share intent */
if (intent != null)
mShareActionProvider.setShareIntent(intent);
return super.onCreateOptionsMenu(menu);
}
/** Returns a share intent */
private Intent getDefaultShareIntent() {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, "Assunto");
intent.putExtra(Intent.EXTRA_TEXT, "Conteúdo!!!");
return intent;
}
}
谁能帮我?