android序列化异常,Android序列化出现java.lang.RuntimeException: Parcelable encountered IOException writing seri...

bug

java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.loan.market.bean.ShopBean$DataBean)

出现的场景

val intent = Intent(context, DetailActivity::class.java)

val bundle = Bundle()

bundle.putSerializable("databeans", databeans[position])//序列化

intent.putExtras(bundle)

context.startActivity(intent)

分析

因为我的ShopBean里面嵌套一个DataBean,DataBean嵌套了LoanProductRequiresBean ,DataBean序列化了,而ShopBean和LoanProductRequiresBean 没有序列化,导致 java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.loan.market.bean.ShopBean$DataBean),纠错:将LoanProductRequiresBean 序列化:

class ShopBean{

var code: Int = 0

var isSuccess: Boolean = false

var message: String? = null

var page: Any? = null

var data: ArrayList? = null

class DataBean : Serializable{

var id: Int = 0

var createTime: Long = 0

var modifyTime: Long = 0

var status: Int = 0

var sortWeight: Int = 0

var productName: String? = null

var bannerUrl: String? = null

var loanMoney: Long? = null

var applyDay: String? = null

var interest: String? = null

var loanTerm: String? = null

var loanRemarks: String? = null

var forwardUrl: String? = null

var loanFlow1: String? = null

var loanFlow2: String? = null

var loanFlow3: String? = null

var loanFlow4: String? = null

var newDate: Long = 0

var googleDate: Long = 0

var loanProductRequires: List? = null

class LoanProductRequiresBean : Serializable{

var id: Int = 0

var createTime: Long = 0

var modifyTime: Any? = null

var productId: Int = 0

var description: String? = null

}

}

}

总结:

如果一个类序列化,则将这个类所有嵌套的实体类都实现序列化。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值