1. 程式人生 > >Android 異常 UncaughtException detected: java.lang.RuntimeException: Parcelable encountered IOExcepti

Android 異常 UncaughtException detected: java.lang.RuntimeException: Parcelable encountered IOExcepti

異常資訊:
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>
 * 郵箱:  
[email protected]
*/
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 進行序列化。