ShareActionProvider与android中的支持库无法正常工作

时间:2015-05-14 18:35:40

标签: android shareactionprovider

我陷入了这个忙碌的错误,在检查了几乎所有相关问题之后无法修复。 我有一个应用程序,我在我的操作栏中使用SharActionProvider来共享一些支持AppCompat库的内容。 这是我的相关代码: 在活动中:

@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu items for use in the action bar
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.cafe__detail, menu);
        MenuItem item = menu.findItem(R.id.share);
        mShareActionProvider =  (ShareActionProvider) MenuItemCompat.getActionProvider(item); 
            mShareActionProvider.setShareIntent(getDefaultIntent());
        return super.onCreateOptionsMenu(menu);
    }

    private Intent getDefaultIntent() {
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_SEND);
        intent.putExtra(Intent.EXTRA_TEXT, "testing text");
        intent.setType("text/plain");       
        return intent;
    }

这里是所有进口。

import android.support.v4.app.FragmentManager;
import android.support.v4.view.MenuItemCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.ShareActionProvider;

我也在从ActionBarActivity扩展我的活动。 这是manu中的xml。

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:MyApp="http://schemas.android.com/apk/res-auto"
    tools:context="com.MyApp.Cafe_Detail" >



    <item android:id="@+id/share"
          android:title="@string/action_share"
          android:icon="@drawable/abc_ic_menu_share_holo_dark"
          MyApp:showAsAction="ifRoom"
          MyApp:actionProviderClass="android.support.v7.widget.ShareActionProvider" />    
</menu>

现在一切都是,当我点击可用应用程序显示的共享按钮列表时,但当我点击其中一个时,应用程序崩溃。和零点异常抛出。 Log cat显示了这个

05-14 18:30:01.942: E/AndroidRuntime(4818): FATAL EXCEPTION: main
05-14 18:30:01.942: E/AndroidRuntime(4818): java.lang.NullPointerException
05-14 18:30:01.942: E/AndroidRuntime(4818):     at android.support.v7.internal.widget.ActivityChooserView.updateAppearance(ActivityChooserView.java:510)
05-14 18:30:01.942: E/AndroidRuntime(4818):     at android.support.v7.internal.widget.ActivityChooserView.access$400(ActivityChooserView.java:66)
05-14 18:30:01.942: E/AndroidRuntime(4818):     at android.support.v7.internal.widget.ActivityChooserView$3.onChanged(ActivityChooserView.java:247)
05-14 18:30:01.942: E/AndroidRuntime(4818):     at android.database.DataSetObservable.notifyChanged(DataSetObservable.java:37)
05-14 18:30:01.942: E/AndroidRuntime(4818):     at android.widget.BaseAdapter.notifyDataSetChanged(BaseAdapter.java:50)
05-14 18:30:01.942: E/AndroidRuntime(4818):     at android.support.v7.internal.widget.ActivityChooserView$1.onChanged(ActivityChooserView.java:127)
05-14 18:30:01.942: E/AndroidRuntime(4818):     at android.database.DataSetObservable.notifyChanged(DataSetObservable.java:37)
05-14 18:30:01.942: E/AndroidRuntime(4818):     at android.support.v7.internal.widget.ActivityChooserModel.addHisoricalRecord(ActivityChooserModel.java:749)
05-14 18:30:01.942: E/AndroidRuntime(4818):     at android.support.v7.internal.widget.ActivityChooserModel.chooseActivity(ActivityChooserModel.java:488)
05-14 18:30:01.942: E/AndroidRuntime(4818):     at android.support.v7.internal.widget.ActivityChooserView$Callbacks.onItemClick(ActivityChooserView.java:553)
05-14 18:30:01.942: E/AndroidRuntime(4818):     at android.widget.AdapterView.performItemClick(AdapterView.java:298)
05-14 18:30:01.942: E/AndroidRuntime(4818):     at android.widget.AbsListView.performItemClick(AbsListView.java:1086)
05-14 18:30:01.942: E/AndroidRuntime(4818):     at android.widget.AbsListView$PerformClick.run(AbsListView.java:2855)
05-14 18:30:01.942: E/AndroidRuntime(4818):     at android.widget.AbsListView$1.run(AbsListView.java:3529)
05-14 18:30:01.942: E/AndroidRuntime(4818):     at android.os.Handler.handleCallback(Handler.java:615)
05-14 18:30:01.942: E/AndroidRuntime(4818):     at android.os.Handler.dispatchMessage(Handler.java:92)
05-14 18:30:01.942: E/AndroidRuntime(4818):     at android.os.Looper.loop(Looper.java:137)
05-14 18:30:01.942: E/AndroidRuntime(4818):     at android.app.ActivityThread.main(ActivityThread.java:4745)
05-14 18:30:01.942: E/AndroidRuntime(4818):     at java.lang.reflect.Method.invokeNative(Native Method)
05-14 18:30:01.942: E/AndroidRuntime(4818):     at java.lang.reflect.Method.invoke(Method.java:511)
05-14 18:30:01.942: E/AndroidRuntime(4818):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
05-14 18:30:01.942: E/AndroidRuntime(4818):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
05-14 18:30:01.942: E/AndroidRuntime(4818):     at dalvik.system.NativeStart.main(Native Method)
崩溃一次后,它甚至不会打开活动,并抛出相同的异常。 有人愿意帮助我吗?

0 个答案:

没有答案