Android NullPointerException in Instrumentation.execStartActivity

天大地大妈咪最大 提交于 2019-12-03 10:48:29

问题


I keep getting the bellow exception from some users:

java.lang.NullPointerException
    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1414)
    at android.app.Activity.startActivityForResult(Activity.java:2880)
    at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:817)
    at android.app.Activity.startActivity(Activity.java:2986)
    at com.google.android.gms.internal.bb$5.onClick(Unknown Source)
    at android.view.View.performClick(View.java:2535)
    at android.view.View$PerformClick.run(View.java:9130)
    at android.os.Handler.handleCallback(Handler.java:618)
    at android.os.Handler.dispatchMessage(Handler.java:123)
    at android.os.Looper.loop(SourceFile:351)
    at android.app.ActivityThread.main(ActivityThread.java:3826)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:538)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:969)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:727)
    at dalvik.system.NativeStart.main(Native Method)

I've found a similar problem here but it's not taken care of since April. All I know is that it was reproduced on a Samsung Galaxy Y (GT-S5360) and I'm using Google Maps Android API v2.

Do you have any idea how can I make a workaround for this?


回答1:


I have the same error, I also use Google Maps API. It seems to happen on all Android versions and phones. Just to mention few:

AN10DG3, GT-I8190, F815, GT-I9300, GOOPHONE, HTC One, KFTT, MID8127, KFAPWI, AN10DG3

java.lang.NullPointerException
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1409)
at android.app.Activity.startActivityForResult(Activity.java:3351)
at android.app.Activity.startActivityForResult(Activity.java:3312)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:839)
at android.app.Activity.startActivity(Activity.java:3522)
at android.app.Activity.startActivity(Activity.java:3490)
at com.google.android.gms.dynamic.a$5.onClick(Unknown Source)
at android.view.View.performClick(View.java:4084)
at android.view.View$PerformClick.run(View.java:16966)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method) 

as I read somewhere, solution is:

Above mentioned problem can occur if you have emulator or device in which google play services are not installed. I don't have perfect solution but I figured out some work around to save your app from crashing. In this case you have to follow simple steps

  1. Override startActivityForResult(intent, requestcode)
  2. In startActivityForResult add super call super.startActivityForResult in try catch and catch the NullPointerException

Easy its done Now you can trap the nullpointerexception here and add your error handling in catch

@Override
public void startActivityForResult(Intent intent, int requestCode) {
    try {
        super.startActivityForResult(intent, requestCode);
    } catch (Exception e) {
        // fixes Google Maps bug: http://stackoverflow.com/a/20905954/2075875
    }
}



回答2:


in my case crash in Instrumentation.java

line 1581,

android.util.SeempLog.record_str(377, intent.toString());

intent is null then NPE

not sure how to fix this



来源:https://stackoverflow.com/questions/17549030/android-nullpointerexception-in-instrumentation-execstartactivity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!