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
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
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
I changed this
android:actionProviderClass=widget.ShareActionProvider" />
To this
app:actionProviderClass=support.v7.widget.ShareActionProvider" />