Android之提示java.lang.RuntimeException: Parcel: unable to marshal value Image问题

简介: Android之提示java.lang.RuntimeException: Parcel: unable to marshal value Image问题

1 问题

使用Intent携带数据(putExtra)跳转activity,提示如下错误

04-18 22:42:49.664 16194 16194 E AndroidRuntime: Process: com.appsinnova.android.keepshare, PID: 16194
04-18 22:42:49.664 16194 16194 E AndroidRuntime: java.lang.RuntimeException: Parcel: unable to marshal value Image{id='0', type='null', createTime='null', urls=ImageUrl{raw='/storage/emulated/0/images/20200409_223150.jpg', full='null', regular='null', small='null', thumb='null'}, date='null', isSelect=false}
04-18 22:42:49.664 16194 16194 E AndroidRuntime:        at android.os.Parcel.writeValue(Parcel.java:1680)
04-18 22:42:49.664 16194 16194 E AndroidRuntime:        at android.os.Parcel.writeList(Parcel.java:979)
04-18 22:42:49.664 16194 16194 E AndroidRuntime:        at android.os.Parcel.writeValue(Parcel.java:1627)
04-18 22:42:49.664 16194 16194 E AndroidRuntime:        at android.os.Parcel.writeArrayMapInternal(Parcel.java:891)
04-18 22:42:49.664 16194 16194 E AndroidRuntime:        at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1579)
04-18 22:42:49.664 16194 16194 E AndroidRuntime:        at android.os.Bundle.writeToParcel(Bundle.java:1233)
04-18 22:42:49.664 16194 16194 E AndroidRuntime:        at android.os.Parcel.writeBundle(Parcel.java:931)
04-18 22:42:49.664 16194 16194 E AndroidRuntime:        at android.content.Intent.writeToParcel(Intent.java:10037)
04-18 22:42:49.664 16194 16194 E AndroidRuntime:        at android.app.IActivityManager$Stub$Proxy.startActivity(IActivityManager.java:3636)
04-18 22:42:49.664 16194 16194 E AndroidRuntime:        at android.app.Instrumentation.execStartActivity(Instrumentation.java:1669)
04-18 22:42:49.664 16194 16194 E AndroidRuntime:        at android.app.Activity.startActivityForResult(Activity.java:4762)
04-18 22:42:49.664 16194 16194 E AndroidRuntime:        at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:676)
04-18 22:42:49.664 16194 16194 E AndroidRuntime:        at android.app.Activity.startActivityForResult(Activity.java:4691)
04-18 22:42:49.664 16194 16194 E AndroidRuntime:        at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:663)
04-18 22:42:49.664 16194 16194 E AndroidRuntime:        at com.skyunion.android.base.RxBaseActivity.startActivityForResult(RxBaseActivity.java:372)
04-18 22:42:49.664 16194 16194 E AndroidRuntime:        at android.app.Activity.startActivity(Activity.java:5081)
04-18 22:42:49.664 16194 16194 E AndroidRuntime:        at android.app.Activity.startActivity(Activity.java:5049)
04-18 22:42:49.664 16194 16194 E AndroidRuntime:        at com.skyunion.android.base.RxBaseActivity.startActivity(RxBaseActivity.java:366)
04-18 22:42:49.664 16194 16194 E AndroidRuntime:        at com.appsinnova.android.keepshare.account.MyLoveActivity.imageClick(MyLoveActivity.kt:450)
04-18 22:42:49.664 16194 16194 E AndroidRuntime:        at com.appsinnova.android.keepshare.account.favorite.adapter.MyFavoriteAdapter$4.onClick(MyFavoriteAdapter.java:295)
04-18 22:42:49.664 16194 16194 E AndroidRuntime:        at android.view.View.performClick(View.java:6724)
04-18 22:42:49.664 16194 16194 E AndroidRuntime:        at android.view.View.performClickInternal(View.java:6682)
04-18 22:42:49.664 16194 16194 E AndroidRuntime:        at android.view.View.access$3400(View.java:797)
04-18 22:42:49.664 16194 16194 E AndroidRuntime:        at android.view.View$PerformClick.run(View.java:26473)
04-18 22:42:49.664 16194 16194 E AndroidRuntime:        at android.os.Handler.handleCallback(Handler.java:873)
04-18 22:42:49.664 16194 16194 E AndroidRuntime:        at android.os.Handler.dispatchMessage(Handler.java:99)
04-18 22:42:49.664 16194 16194 E AndroidRuntime:        at android.os.Looper.loop(Looper.java:226)
04-18 22:42:49.664 16194 16194 E AndroidRuntime:        at android.app.ActivityThread.main(ActivityThread.java:7223)
04-18 22:42:49.664 16194 16194 E AndroidRuntime:        at java.lang.reflect.Method.invoke(Native Method)
04-18 22:42:49.664 16194 16194 E AndroidRuntime:        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:576)
04-18 22:42:49.664 16194 16194 E AndroidRuntime:        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:961)
04-18 22:42:49.672   601   642 I vendor.mediatek.hardware.power@2.1-impl: notifyAppState_2_1 pack:com.appsinnova.android.keepshare, act:com.appsinnova.android.keepshare, pid:16194, uid:10296, state:3


然后我在这类的子类里面添加实现Serializable接口

implements Serializable


然后运行依然报错

04-18 22:47:36.958 19445 19445 E AndroidRuntime: java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.appsinnova.android.keepshare.data.net.model.FavoriteModel$Image)
04-18 22:47:36.958 19445 19445 E AndroidRuntime:        at android.os.Parcel.writeSerializable(Parcel.java:1730)
04-18 22:47:36.958 19445 19445 E AndroidRuntime:        at android.os.Parcel.writeValue(Parcel.java:1678)
04-18 22:47:36.958 19445 19445 E AndroidRuntime:        at android.os.Parcel.writeList(Parcel.java:979)
04-18 22:47:36.958 19445 19445 E AndroidRuntime:        at android.os.Parcel.writeValue(Parcel.java:1627)
04-18 22:47:36.958 19445 19445 E AndroidRuntime:        at android.os.Parcel.writeArrayMapInternal(Parcel.java:891)
04-18 22:47:36.958 19445 19445 E AndroidRuntime:        at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1579)
04-18 22:47:36.958 19445 19445 E AndroidRuntime:        at android.os.Bundle.writeToParcel(Bundle.java:1233)
04-18 22:47:36.958 19445 19445 E AndroidRuntime:        at android.os.Parcel.writeBundle(Parcel.java:931)
04-18 22:47:36.958 19445 19445 E AndroidRuntime:        at android.content.Intent.writeToParcel(Intent.java:10037)
04-18 22:47:36.958 19445 19445 E AndroidRuntime:        at android.app.IActivityManager$Stub$Proxy.startActivity(IActivityManager.java:3636)
04-18 22:47:36.958 19445 19445 E AndroidRuntime:        at android.app.Instrumentation.execStartActivity(Instrumentation.java:1669)
04-18 22:47:36.958 19445 19445 E AndroidRuntime:        at android.app.Activity.startActivityForResult(Activity.java:4762)
04-18 22:47:36.958 19445 19445 E AndroidRuntime:        at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:676)
04-18 22:47:36.958 19445 19445 E AndroidRuntime:        at android.app.Activity.startActivityForResult(Activity.java:4691)
04-18 22:47:36.958 19445 19445 E AndroidRuntime:        at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:663)
04-18 22:47:36.958 19445 19445 E AndroidRuntime:        at com.skyunion.android.base.RxBaseActivity.startActivityForResult(RxBaseActivity.java:372)
04-18 22:47:36.958 19445 19445 E AndroidRuntime:        at android.app.Activity.startActivity(Activity.java:5081)
04-18 22:47:36.958 19445 19445 E AndroidRuntime:        at android.app.Activity.startActivity(Activity.java:5049)
04-18 22:47:36.958 19445 19445 E AndroidRuntime:        at com.skyunion.android.base.RxBaseActivity.startActivity(RxBaseActivity.java:366)
04-18 22:47:36.958 19445 19445 E AndroidRuntime:        at com.appsinnova.android.keepshare.account.MyLoveActivity.imageClick(MyLoveActivity.kt:450)
04-18 22:47:36.958 19445 19445 E AndroidRuntime:        at com.appsinnova.android.keepshare.account.favorite.adapter.MyFavoriteAdapter$4.onClick(MyFavoriteAdapter.java:295)
04-18 22:47:36.958 19445 19445 E AndroidRuntime:        at android.view.View.performClick(View.java:6724)
04-18 22:47:36.958 19445 19445 E AndroidRuntime:        at android.view.View.performClickInternal(View.java:6682)
04-18 22:47:36.958 19445 19445 E AndroidRuntime:        at android.view.View.access$3400(View.java:797)
04-18 22:47:36.958 19445 19445 E AndroidRuntime:        at android.view.View$PerformClick.run(View.java:26473)
04-18 22:47:36.958 19445 19445 E AndroidRuntime:        at android.os.Handler.handleCallback(Handler.java:873)
04-18 22:47:36.958 19445 19445 E AndroidRuntime:        at android.os.Handler.dispatchMessage(Handler.java:99)
04-18 22:47:36.958 19445 19445 E AndroidRuntime:        at android.os.Looper.loop(Looper.java:226)
04-18 22:47:36.958 19445 19445 E AndroidRuntime:        at android.app.ActivityThread.main(ActivityThread.java:7223)
04-18 22:47:36.958 19445 19445 E AndroidRuntime:        at java.lang.reflect.Method.invoke(Native Method)
04-18 22:47:36.958 19445 19445 E AndroidRuntime:        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:576)
04-18 22:47:36.958 19445 19445 E AndroidRuntime:        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:961)
04-18 22:47:36.958 19445 19445 E AndroidRuntime: Caused by: java.io.NotSerializableException: com.appsinnova.android.keepshare.data.net.model.FavoriteModel$ImageUrl
04-18 22:47:36.958 19445 19445 E AndroidRuntime:        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1240)
04-18 22:47:36.958 19445 19445 E AndroidRuntime:        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1604)
04-18 22:47:36.958 19445 19445 E AndroidRuntime:        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1565)
04-18 22:47:36.958 19445 19445 E AndroidRuntime:        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1488)
04-18 22:47:36.958 19445 19445 E AndroidRuntime:        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1234)
04-18 22:47:36.958 19445 19445 E AndroidRuntime:        at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:354)
04-18 22:47:36.958 19445 19445 E AndroidRuntime:        at android.os.Parcel.writeSerializable(Parcel.java:1725)
04-18 22:47:36.958 19445 19445 E AndroidRuntime:        ... 31 more

很明显啊,最外面的类也需要实现 Serializable接口,改了还是有问题,因为它的子类里面的子类也需要实现这个Serializable接口


2 解决办法

在这个类的外面被包裹的类和它的子类都实现 Serializable接口就可以了



相关文章
|
1月前
|
JSON Java 关系型数据库
Java更新数据库报错:Data truncation: Cannot create a JSON value from a string with CHARACTER SET 'binary'.
在Java中,使用mybatis-plus更新实体类对象到mysql,其中一个字段对应数据库中json数据类型,更新时报错:Data truncation: Cannot create a JSON value from a string with CHARACTER SET 'binary'.
70 4
Java更新数据库报错:Data truncation: Cannot create a JSON value from a string with CHARACTER SET 'binary'.
|
1月前
|
存储 Java API
Java交换map的key和value值
通过本文介绍的几种方法,可以在Java中实现Map键值对的交换。每种方法都有其优缺点,具体选择哪种方法应根据实际需求和场景决定。对于简单的键值对交换,可以使用简单遍历法或Java 8的Stream API;对于需要处理值不唯一的情况,可以使用集合存储或Guava的Multimap。希望本文对您理解和实现Java中的Map键值对交换有所帮助。
40 1
|
29天前
|
Java
Unable to obtain OffsetDateTime from TemporalAccessor: {},ISO resolved to 2024-11-26T20:55:26 of type java.time.format.Parsed
Unable to obtain OffsetDateTime from TemporalAccessor: {},ISO resolved to 2024-11-26T20:55:26 of type java.time.format.Parsed
34 0
|
3月前
|
Java Android开发 C++
🚀Android NDK开发实战!Java与C++混合编程,打造极致性能体验!📊
在Android应用开发中,追求卓越性能是不变的主题。本文介绍如何利用Android NDK(Native Development Kit)结合Java与C++进行混合编程,提升应用性能。从环境搭建到JNI接口设计,再到实战示例,全面展示NDK的优势与应用技巧,助你打造高性能应用。通过具体案例,如计算斐波那契数列,详细讲解Java与C++的协作流程,帮助开发者掌握NDK开发精髓,实现高效计算与硬件交互。
169 1
|
4月前
|
存储 搜索推荐 Java
探索安卓开发中的自定义视图:打造个性化UI组件Java中的异常处理:从基础到高级
【8月更文挑战第29天】在安卓应用的海洋中,一个独特的用户界面(UI)能让应用脱颖而出。自定义视图是实现这一目标的强大工具。本文将通过一个简单的自定义计数器视图示例,展示如何从零开始创建一个具有独特风格和功能的安卓UI组件,并讨论在此过程中涉及的设计原则、性能优化和兼容性问题。准备好让你的应用与众不同了吗?让我们开始吧!
|
4月前
|
Java 调度 Android开发
Android经典实战之Kotlin的delay函数和Java中的Thread.sleep有什么不同?
本文介绍了 Kotlin 中的 `delay` 函数与 Java 中 `Thread.sleep` 方法的区别。两者均可暂停代码执行,但 `delay` 适用于协程,非阻塞且高效;`Thread.sleep` 则阻塞当前线程。理解这些差异有助于提高程序效率与可读性。
87 1
|
4月前
|
JSON 前端开发 JavaScript
JSON parse error: Cannot deserialize value of type `java.lang.Integer` from Boolean value
这篇文章讨论了前端Vue应用向后端Spring Boot服务传输数据时发生的类型不匹配问题,即后端期望接收的字段类型为`int`,而前端实际传输的类型为`Boolean`,导致无法反序列化的问题,并提供了问题的诊断和解决方案。
JSON parse error: Cannot deserialize value of type `java.lang.Integer` from Boolean value
|
4月前
|
Android开发
Cannot create android app from an archive...containing both DEX and Java-bytecode content
Cannot create android app from an archive...containing both DEX and Java-bytecode content
48 2
|
4月前
|
Java Android开发
解决Android编译报错:Unable to make field private final java.lang.String java.io.File.path accessible
解决Android编译报错:Unable to make field private final java.lang.String java.io.File.path accessible
663 1
|
4月前
|
IDE Java Linux
探索安卓开发:从基础到进阶的旅程Java中的异常处理:从基础到高级
【8月更文挑战第30天】在这个数字时代,移动应用已经成为我们日常生活中不可或缺的一部分。安卓系统由于其开放性和灵活性,成为了开发者的首选平台之一。本文将带领读者踏上一段从零开始的安卓开发之旅,通过深入浅出的方式介绍安卓开发的基础知识、核心概念以及进阶技巧。我们将一起构建一个简单的安卓应用,并探讨如何优化代码以提高性能和应用的用户体验。无论你是初学者还是有一定经验的开发者,这篇文章都将为你提供宝贵的知识和启发。