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接口就可以了
赞 (0)