bug
java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.loan.market.bean.ShopBean$DataBean)
出現(xiàn)的場景
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 沒有序列化,導(dǎo)致 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<ShopBean.DataBean>? = 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<LoanProductRequiresBean>? = null
class LoanProductRequiresBean : Serializable{
var id: Int = 0
var createTime: Long = 0
var modifyTime: Any? = null
var productId: Int = 0
var description: String? = null
}
}
}
總結(jié):
如果一個類序列化,則將這個類所有嵌套的實體類都實現(xiàn)序列化危融。