当我试图从intent执行getExtra时,我得到了这个错误。getIntent().getParcelableArrayListExtra(KEY)
当我更改密钥时,错误就变成了java.lang.NullPointerException
。我不能理解为什么会发生这种事。有许多Parcelable对象工作得很好。这也工作得很好(所以,Parcelable对象没有问题),直到我将其他对象放入具有不同键值对的意图中,也可能做错了什么。有人能告诉我为什么会发生这个错误吗?这种类型的错误背后可能的原因是什么?
您还可以查看日志。
02-24 02:55:21.927 28362-28362/com.abc.app E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.abc.app, PID: 28362
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.abc.app/com.abc.app.activity.FinalActivity}: java.lang.IllegalArgumentException: Duplicate key in ArrayMap: null
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2493)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2555)
at android.app.ActivityThread.access$800(ActivityThread.java:176)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1437)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5576)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:956)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:751)
Caused by: java.lang.IllegalArgumentException: Duplicate key in ArrayMap: null
at android.util.ArrayMap.validate(ArrayMap.java:555)
at android.os.Parcel.readArrayMapInternal(Parcel.java:2486)
at android.os.BaseBundle.unparcel(BaseBundle.java:221)
at android.os.Bundle.getParcelableArrayList(Bundle.java:848)
at android.content.Intent.getParcelableArrayListExtra(Intent.java:5099)
at com.abc.app.activity.FinalActivity.onCreate(FinalActivity.java:60)
at android.app.Activity.performCreate(Activity.java:6005)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1111)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2446)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2555)
at android.app.ActivityThread.access$800(ActivityThread.java:176)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1437)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5576)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:956)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:751)
当我改变键值时,我会在日志中看到这一点,同时还会出现空指针异常
02-24 03:01:38.074 32206-32206/com.abc.app W/ArrayMap: New hash 0 is before end of array hash 1374673561 at index 4 key null
java.lang.RuntimeException: here
at android.util.ArrayMap.append(ArrayMap.java:510)
at android.os.Parcel.readArrayMapInternal(Parcel.java:2483)
at android.os.BaseBundle.unparcel(BaseBundle.java:221)
at android.os.Bundle.getParcelableArrayList(Bundle.java:848)
at android.content.Intent.getParcelableArrayListExtra(Intent.java:5099)
at com.abc.app.activity.FinalActivity.onCreate(FinalActivity.java:60)
at android.app.Activity.performCreate(Activity.java:6005)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1111)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2446)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2555)
at android.app.ActivityThread.access$800(ActivityThread.java:176)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1437)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5576)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:956)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:751)
发布于 2017-12-20 21:06:55
Write to Parcelable和read from Parcelable的顺序应该是相同的。或者你把null放在额外值中。
https://stackoverflow.com/questions/35588311
复制相似问题