Parcel android.os.Parcel@439e4cf0

本文探讨了在Android应用中使用Parcel传递复杂数据结构时出现的崩溃问题。具体表现为因数据读取顺序不一致导致部分设备上应用闪退。文章详细解释了问题原因,并提供了正确的数据读写顺序示例来确保数据的一致性和应用程序的稳定性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

https://www.3566t.com/news/show-5683902.html



项目的报错

:Unable to start activity ComponentInfo{com.jindaozi.app/com.jindaozi.app.activity.financ.SubmitPayActivity}: 
java.lang.RuntimeException: Parcel android.os.Parcel@439e4cf0: Unmarshalling unknown type code 7471216 at offset 292


原因:在传递parcel传递数据时候,数据的读取顺序没有一致,部分手机会出现闪退现象


解决方法:读取的顺序应该一致

 /**
     * 这里的读的顺序必须与writeToParcel(Parcel dest, int flags)方法中
     * 写的顺序一致,否则数据会有差错,比如你的读取顺序如果是:
     * nickname = source.readString();
     * username=source.readString();
     * age = source.readInt();
     * 即调换了username和nickname的读取顺序,那么你会发现你拿到的username是nickname的数据,
     * 而你拿到的nickname是username的数据
     * @param source
     */
    public Person(Parcel source) {
        username = source.readString();
        nickname=source.readString();
        age = source.readInt();
    }
    /**
     * 把值写入Parcel中
     */
    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(username);
        dest.writeString(nickname);
        dest.writeInt(age);
    }




07-21 12:41:47.502 1144 2915 W ContextImpl: Calling a method in the system process without a qualified user: android.app.ContextImpl.startService:1669 com.android.server.policy.PhoneWindowManager.interceptKeyBeforeDispatching:2866 com.android.server.wm.InputManagerCallback.interceptKeyBeforeDispatching:336 com.android.server.input.InputManagerService.interceptKeyBeforeDispatching:1993 <bottom of call stack> 07-21 12:41:47.600 1144 2915 V WindowManager: keyCode == KeyEvent.KEYCODE_F1 --------- beginning of crash 07-21 12:41:48.699 11171 11189 F libc : Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 in tid 11189 (Binder:11171_3), pid 11171 (com.zebra.sdl) 07-21 12:41:48.821 11404 11404 F DEBUG : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** 07-21 12:41:48.822 11404 11404 F DEBUG : Build fingerprint: 'Zebra/ET45A/ET45L:11/11-17-20.00-RN-U00-STD-GSE-04/45:user/release-keys' 07-21 12:41:48.822 11404 11404 F DEBUG : Revision: '0' 07-21 12:41:48.823 11404 11404 F DEBUG : ABI: 'arm64' 07-21 12:41:48.824 11404 11404 F DEBUG : Timestamp: 2025-07-21 12:41:48+0800 07-21 12:41:48.824 11404 11404 F DEBUG : pid: 11171, tid: 11189, name: Binder:11171_3 >>> com.zebra.sdl <<< 07-21 12:41:48.824 11404 11404 F DEBUG : uid: 1000 07-21 12:41:48.824 11404 11404 F DEBUG : signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 07-21 12:41:48.825 11404 11404 F DEBUG : Cause: null pointer dereference 07-21 12:41:48.825 11404 11404 F DEBUG : x0 0000000000000000 x1 00000076f4446000 x2 0000000000000280 x3 0000000000000000 07-21 12:41:48.825 11404 11404 F DEBUG : x4 00000076f4446280 x5 0000000000000280 x6 9397958279807d7a x7 89918992878a8c8d 07-21 12:41:48.825 11404 11404 F DEBUG : x8 00000076f4446000 x9 0000000000000000 x10 b4000077b43a11d0 x11 0000000000070800 07-21 12:41:48.825 11404 11404 F DEBUG : x12 7a76737371747477 x13 787578787e797780 x14 0028fb4a1c8279e4 x15 0000000000000000 07-21 12:41:48.825 11404 11404 F DEBUG : x16 000000769cd64cf0 x17 00000079985a5480 x18 000000769f312000 x19 b4000077b43a11d0 07-21 12:41:48.825 11404 11404 F DEBUG : x20 b4000077c438cc10 x21 0000000000000000 x22 0000000000000000 x23 0000000000000280 07-21 12:41:48.825 11404 11404 F DEBUG : x24 00000076f4446000 x25 0000000000000000 x26 0000000000000000 x27 00000076a03f4000 07-21 12:41:48.825 11404 11404 F DEBUG : x28 0000000000000000 x29 00000076a03f3720 07-21 12:41:48.826 11404 11404 F DEBUG : lr 000000769cd5c5a0 sp 00000076a03f36a0 pc 00000079985a5408 pst 0000000020000000 07-21 12:41:48.855 11404 11404 F DEBUG : backtrace: 07-21 12:41:48.855 11404 11404 F DEBUG : #00 pc 000000000004a408 /apex/com.android.runtime/lib64/bionic/libc.so (__memcpy+248) (BuildId: 3dd99fe7a181e7428f58a10f32f9fd0e) 07-21 12:41:48.856 11404 11404 F DEBUG : #01 pc 000000000000559c /system/lib64/libbarcodereader90.so (JNIBCReaderContext::copyAndPost(_JNIEnv*, android::sp<android::IMemory> const&, int)+376) (BuildId: 9f598355db3423c5cf018d4177259431) 07-21 12:41:48.856 11404 11404 F DEBUG : #02 pc 0000000000005944 /system/lib64/libbarcodereader90.so (JNIBCReaderContext::postData(int, android::sp<android::IMemory> const&, camera_frame_metadata*)+164) (BuildId: 9f598355db3423c5cf018d4177259431) 07-21 12:41:48.856 11404 11404 F DEBUG : #03 pc 0000000000041848 /system/lib64/libcamera_client.so (android::Camera::dataCallback(int, android::sp<android::IMemory> const&, camera_frame_metadata*)+144) (BuildId: 8b1f1779ad096e52011dd41ceea7925c) 07-21 12:41:48.856 11404 11404 F DEBUG : #04 pc 00000000000578ac /system/lib64/libcamera_client.so (android::hardware::BnCameraClient::onTransact(unsigned int, android::Parcel const&, android::Parcel*, unsigned int)+1380) (BuildId: 8b1f1779ad096e52011dd41ceea7925c) 07-21 12:41:48.856 11404 11404 F DEBUG : #05 pc 0000000000049860 /system/lib64/libbinder.so (android::BBinder::transact(unsigned int, android::Parcel const&, android::Parcel*, unsigned int)+232) (BuildId: 097b765cd1046eeb5516049d57e24f53) 07-21 12:41:48.856 11404 11404 F DEBUG : #06 pc 00000000000523a0 /system/lib64/libbinder.so (android::IPCThreadState::executeCommand(int)+1032) (BuildId: 097b765cd1046eeb5516049d57e24f53) 07-21 12:41:48.856 11404 11404 F DEBUG : #07 pc 0000000000051ee4 /system/lib64/libbinder.so (android::IPCThreadState::getAndExecuteCommand()+156) (BuildId: 097b765cd1046eeb5516049d57e24f53) 07-21 12:41:48.856 11404 11404 F DEBUG : #08 pc 0000000000052724 /system/lib64/libbinder.so (android::IPCThreadState::joinThreadPool(bool)+60) (BuildId: 097b765cd1046eeb5516049d57e24f53) 07-21 12:41:48.857 11404 11404 F DEBUG : #09 pc 0000000000078b90 /system/lib64/libbinder.so (android::PoolThread::threadLoop()+24) (BuildId: 097b765cd1046eeb5516049d57e24f53) 07-21 12:41:48.857 11404 11404 F DEBUG : #10 pc 000000000001567c /system/lib64/libutils.so (android::Thread::_threadLoop(void*)+260) (BuildId: b81fad2b6b7b7f85c6217d2cb80c9e61) 07-21 12:41:48.857 11404 11404 F DEBUG : #11 pc 00000000000a0dac /system/lib64/libandroid_runtime.so (android::AndroidRuntime::javaThreadShell(void*)+140) (BuildId: 8e83d81f587b91e2b3599dfb182e7d9c) 07-21 12:41:48.857 11404 11404 F DEBUG : #12 pc 0000000000014f14 /system/lib64/libutils.so (thread_data_t::trampoline(thread_data_t const*)+412) (BuildId: b81fad2b6b7b7f85c6217d2cb80c9e61) 07-21 12:41:48.857 11404 11404 F DEBUG : #13 pc 00000000000b0bd8 /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+64) (BuildId: 3dd99fe7a181e7428f58a10f32f9fd0e) 07-21 12:41:48.857 11404 11404 F DEBUG : #14 pc 00000000000505d0 /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+64) (BuildId: 3dd99fe7a181e7428f58a10f32f9fd0e)
最新发布
07-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值