Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intent.migrateExtraStreamToClipData() on a null object reference

Started getting this error in the production version of my app.

java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.content.Intent.migrateExtraStreamToClipData()' on a null object reference

There's no clear line at which this actually occurs but I recently changed my support library version to 24.0.0. Here's the full stacktrace:

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.content.Intent.migrateExtraStreamToClipData()' on a null object reference
   at android.app.Instrumentation.execStartActivity(Instrumentation.java:1494)
   at android.app.Activity.startActivityForResult(Activity.java:3745)
   at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:48)
   at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:75)
   at android.app.Activity.startActivityForResult(Activity.java:3706)
   at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:871)
   at com.google.android.gms.common.internal.zzi$1.zztD(Unknown Source)
   at com.google.android.gms.common.internal.zzi.onClick(Unknown Source)
   at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:162)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:135)
   at android.app.ActivityThread.main(ActivityThread.java:5254)
   at java.lang.reflect.Method.invoke(Method.java)
   at java.lang.reflect.Method.invoke(Method.java:372)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

EDIT: I also want to note that 100% of the users getting this error are also rooted. This also occurs on 23.4.0... I also have a potential related error which popped up at the same time which has to do with the Base64.decode function in relation to Firebase.

EDIT 2: I received some help from an Android Dev the other day. They suggested that I update my project's Google Play Services version and it seems to have helped so far. I'll wait a few more days to get the results from my users but the initial logs are promising.

I was previously using 9.0.2 but I'm now on 9.2.0.

EDIT 3: Updating to 9.2.0 didn't help the crashes. I'm still getting the same error from rooted users. I've noted that at the users getting crashes are below Android 6.0 so I'll be testing on a live device and update ASAP.

like image 456
c0deblooded Avatar asked Jun 26 '16 17:06

c0deblooded


3 Answers

Seems like the error occurs on devices where Google Play Services are not installed, passed intent will then be null.

You can make sure intent passed is not null by overriding startActivityForResult method in your Activity.

@Override    
public void startActivityForResult(Intent intent, int requestCode) {
    if (intent == null) {    
        intent = new Intent();        
    }       
    super.startActivityForResult(intent, requestCode);
}
like image 194
MVojtkovszky Avatar answered Oct 16 '22 11:10

MVojtkovszky


This actually worked for me.

For Android 11 (API level 30) or higher, in AndroidManifest.xml,

<queries>
        <package android:name="com.google.android.youtube" />
        <package android:name="com.example.app" />
</queries>

"If your app targets Android 11 (API level 30) or higher and needs to interact with apps other than the ones that are visible automatically, add the element in your app's manifest file. Within the element, specify the other apps by package name."

Refer here for more details.

like image 6
dmukherjee Avatar answered Oct 16 '22 10:10

dmukherjee


This question is a bit old, but I just wanted to share an update on it. According to this Github issue on the GCM project the issue should be solved in Google Play Services version 9.4.0. The accepted answer should work as well (as an intermediate patch), but if you update your Google Play Services library this issue should be solved.

like image 4
Smalls Avatar answered Oct 16 '22 12:10

Smalls