异常:
java.lang.RuntimeException: Parcelable encountered IOException writing serializable object
出现地方:
intent发送:
Intent intent = new Intent(getActivity(), StockDetailActivity.class); ProductModel_out product = (ProductModel_out)parent.getItemAtPosition(position); intent.putExtra("product",product); startActivity(intent);
//得到上个页面传递过来的数据 Intent intent = getIntent(); if (intent == null){ return; } //得到商品信息 product_id =intent.getIntExtra("product_id",-1); productModel_out = (ProductModel_out) intent.getSerializableExtra("product");
问题出现原因:
productModel_out我虽然是实现了serialzable接口,但是
productModel_out类中我还嵌套了其他自定义的实体类,那个实体类没有实现Serialzable接口,所以会出现这类类型转换的异常.
问题解决:
productModel_out类中所有嵌套的实体类都实现SerialZable接口