Android 序列化(Serializable)出現錯誤 java.lang.RuntimeException: Parcelable encountered IOException writing
阿新 • • 發佈:2018-12-26
在傳資料物件的時候,使用Serializable的時候,出現了一個錯誤,
java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.**.Bean)
因為我的bean下面還是還嵌套了其他自定義的實體類,然而這個個實體類沒有實現Serialzable介面,所以會出現這個型別轉換的異常的錯誤.
解決辦法:讓所有的實體類都實現SerialZable介面就可以了。
如下:
public class AddPlanDialogBean implements Serializable {
/**
* order : {"margin_price":133.67,"client_num":"OP171026224746575054"}
* bonus : [{"ub_id":"3","price":200,"total_price":5000,"use_end":"2017-12-19"}]
*/
private OrderEntity order;
private List<BonusEntity> bonus;
public void setOrder(OrderEntity order) {
this .order = order;
}
public void setBonus(List<BonusEntity> bonus) {
this.bonus = bonus;
}
public OrderEntity getOrder() {
return order;
}
public List<BonusEntity> getBonus() {
return bonus;
}
public static class OrderEntity implements Serializable {
/**
* margin_price : 133.67
* client_num : OP171026224746575054
*/
private double margin_price;
private String client_num;
public void setMargin_price(double margin_price) {
this.margin_price = margin_price;
}
public void setClient_num(String client_num) {
this.client_num = client_num;
}
public double getMargin_price() {
return margin_price;
}
public String getClient_num() {
return client_num;
}
}
public static class BonusEntity implements Serializable {
/**
* ub_id : 3
* price : 200
* total_price : 5000
* use_end : 2017-12-19
*/
private String ub_id;
private int price;
private int total_price;
private String use_end;
public void setUb_id(String ub_id) {
this.ub_id = ub_id;
}
public void setPrice(int price) {
this.price = price;
}
public void setTotal_price(int total_price) {
this.total_price = total_price;
}
public void setUse_end(String use_end) {
this.use_end = use_end;
}
public String getUb_id() {
return ub_id;
}
public int getPrice() {
return price;
}
public int getTotal_price() {
return total_price;
}
public String getUse_end() {
return use_end;
}
}
}
本人菜鳥一個,有什麼不對的地方希望大家指出評論,大神勿噴,希望大家一起學習進步!