Below is the code for my Activity
import android.app.Activity;
import android.os.Bundle;
import android.support.v7.widget.ShareActionProvider;
None of the solutions here solved my problem with ShareActionProvider, not casting / returning null. I ended up replacing ShareActionProvider with just an Intent.SEND_ACTION to share images in my app, like presented in Android Developers tutorial: https://developer.android.com/training/sharing/send
Although Google mentions in this tutorial that:
Note: The best way to add a share action item to an ActionBar is to use ShareActionProvider, which became available in API level 14. ShareActionProvider is discussed in the lesson about Adding an Easy Share Action.
I found much simpler to implement just the Intention.SEND_ACTION. Not sure if there are other reasons to implement the ShareActionProvider...