异常信息:
UncaughtException detected: java.lang.RuntimeException: Parcelable encountered IOException writing serializable object
出现原因
在Activity之间传递数据的时候,实现Serializable 接口,出现问题。
实体类
/**
* 作者: pyfysf
* <p>
* qq: 337081267
* <p>
* CSDN: http://blog.csdn.net/pyfysf
* <p>
* 个人博客: http://wintp.top
* <p>
* 时间: 2018/01/2018/1/23 15:07
* <p>
* 邮箱: pyfysf@163.com
*/
public class GoodsBean implements Serializable {
private String createtime;
private String images;
private int clickCount;
private UniUserBean uniUser;
private String mobile;
private String description;
private int catId;
private int createid;
private double price;
private String name;
private int id;
private int status;
第二个Activity
private void exit4Goods(int position) {
if (mGoodLists != null) {
//选择商品名称成功
GoodsBean goodsBean = mGoodLists.get(position);
Intent data = new Intent();
data.putExtra("goodsBean", goodsBean);
setResult(ConstantValues.ACTIVITY_SELECT_GOODS_SUCCESS_CODE, data);
}
}
第一个Activity
if (resultCode == ConstantValues.ACTIVITY_SELECT_GOODS_SUCCESS_CODE) {
// 选择商品成功成功
if (data != null) {
GoodsBean goodsBean = (GoodsBean) data.getSerializableExtra("goodsBean");
}
}
解决方案
实体类GoodsBean 中引用了UniUserBean ,那么不仅仅只把GoodsBean进行序列化,还要把UniUserBean 进行序列化。