Null Pointer exception in using support library share action provider

后端 未结 3 813
时光取名叫无心
时光取名叫无心 2021-01-04 06:06

Below is the code of my Activity . In this I am using the support library appcompat

   import android.content.Intent;
   import android.os.Bundle;
   import          


        
相关标签:
3条回答
  • 2021-01-04 06:36

    If this line

    shareAction.setShareIntent(shareIntent);
    

    is throwing a NullPointerException, this sentence

    (ShareActionProvider) MenuItemCompat.getActionProvider(item);
    

    must be returning null.

    Have a look at the post below, which talks about reasons why this would happen.

    NullPointerException on setShareIntent using ActionBarSherlock

    0 讨论(0)
  • 2021-01-04 06:37

    I found the error. The problem was that support library requires to have a custom prefix and not android:actionProviderClass . What i was doing wrong that i used android:actionProviderClass instead of customprefix:actionProviderClass

    See here: https://developer.android.com/training/basics/actionbar/adding-buttons.html

    0 讨论(0)
  • 2021-01-04 06:39

    I changed this

    android:actionProviderClass=widget.ShareActionProvider" />
    

    To this

    app:actionProviderClass=support.v7.widget.ShareActionProvider" />
    
    0 讨论(0)
提交回复
热议问题