有时应用程序出现崩溃问题,我的崩溃日志显示错误如下:
Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.support.v4.util.SparseArrayCompat.size()' on a null object reference
at android.support.v4.app.FragmentActivity.onSaveInstanceState(FragmentActivity.java:570)
at android.support.v7.app.AppCompatActivity.onSaveInstanceState(AppCompatActivity.java:480)
at android.app.Activity.performSaveInstanceState(Activity.java:1495)
at android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1316)
at android.app.ActivityThread.callCallActivityOnSaveInstanceState(ActivityThread.java:5194)
at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:4519)
at android.app.ActivityThread.handleStopActivity(ActivityThread.java:4582)
at android.app.ActivityThread.access$1300(ActivityThread.java:218)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1747)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6917)
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:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
如何解决此错误?
请提前帮助我。
答案 0 :(得分:0)
好像你试图获取数组对象的size()而不检查对象。设置空检查以避免此异常。
if(array != null ){
int size = array.size();
}
答案 1 :(得分:0)
我认为在尝试传输数据或不匹配类型时,不会获得数组大小。 您的对象映射不正确。 Plz再次检查您的映射。