其他分享
首页 > 其他分享> > 如何修复Android中偏移YYY的Unmarshalling未知类型代码XXX?

如何修复Android中偏移YYY的Unmarshalling未知类型代码XXX?

作者:互联网

由于Unmarshalling异常,我正在恢复应用程序崩溃.我检查了所有Seri​​alizables都没有参数的构造函数,甚至使用ObjectStream检查了所有可序列化(保存到文件并从文件加载).我如何理解导致异常的parcelable偏移的实际类类型:

Parcel android.os.Parcel@42209460: Unmarshalling unknown type code
 2131165303 at offset 3748
         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2080)
         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2105)
         at android.app.ActivityThread.access$600(ActivityThread.java:136)
         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1201)
         at android.os.Handler.dispatchMessage(Handler.java:99)
         at android.os.Looper.loop(Looper.java:137)
         at android.app.ActivityThread.main(ActivityThread.java:4876)
         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:804)
         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:571)
         at com.kdgdev.xtension.core.XtensionMain.main(XtensionMain.java:91)
         at dalvik.system.NativeStart.main(Native Method)
        Caused by: java.lang.RuntimeException: Parcel android.os.Parcel@42209460: Unmarshalling unknown type code 2131165303
 at offset 3748
         at android.os.Parcel.readValue(Parcel.java:2032)
         at android.os.Parcel.readSparseArrayInternal(Parcel.java:2255)
         at android.os.Parcel.readSparseArray(Parcel.java:1687)
         at android.os.Parcel.readValue(Parcel.java:2022)
         at android.os.Parcel.readMapInternal(Parcel.java:2226)
         at android.os.Bundle.unparcel(Bundle.java:223)
         at android.os.Bundle.getSparseParcelableArray(Bundle.java:1232)
        at com.android.internal.policy.impl.PhoneWindow.restoreHierarchyState(PhoneWindow.java:1690)
         at android.app.Activity.onRestoreInstanceState(Activity.java:999)
         at com.actionbarsherlock.app.SherlockFragmentActivity.onRestoreInstanceState(Unknown
 Source)
         at name.myname.android.app.ui.MainActivity.onRestoreInstanceState(Unknown
 Source)
         at android.app.Activity.performRestoreInstanceState(Activity.java:971)
         at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1130)
         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2058)
       ... 12 more

保存的数据包括Bundles和Serializables,所有这些都很好看.

我打算做下一个:

try {
// unmarshalling
} catch (Throwable t) {
// look offset 
}

我如何理解Parcelable偏移的实际类型?

解决方法:

写入和读取parcelables有一些规则.

1-注意类型不匹配.如果你写int,不要试着读长等.

2-注意写入和读取的顺序.在读取和写入时,对象必须处于相同的排序顺序.

这两个都可能导致“解组未知类型代码”.

标签:unmarshalling,parcelable,android,serialization,marshalling
来源: https://codeday.me/bug/20190926/1822007.html