listview.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Intent it = new Intent(getActivity(), ReleaseDetail.class);
final SerializableMap myMap = new SerializableMap();
myMap.setMap(tempList);// 将map数据添加到封装的myMap中
Bundle bundle = new Bundle();
bundle.putSerializable("map1", myMap);
it.putExtras(bundle);
startActivity(it);
getActivity().finish();
}
});
public class SerializableMap implements Serializable {
private static final long serialVersionUID = 3958588986554810147L;
private Map<String, ReleaseContents> map;
public Map<String, ReleaseContents> getMap() {
return map;
}
public void setMap(Map<String, ReleaseContents> tempMap) {
this.map = tempMap;
}
}
ReleaseContents是一个实体类也实现了Serializable 接口还是报以下错误呢!!!
07-12 12:51:58.093: E/AndroidRuntime(12270): java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = XXX.SerializableMap)XXX
查资料说是对象也是要先序列化接口,我ReleaseContents都实现了的呀!请问是哪里错了哦!
黄舟2017-04-17 17:33:33
The classes used under the ReleaseContents
class also need to implement the Serializable
interface. For example, your ReleaseContents
class has an attribute that is Version< /code> class, then this
Version
class may implement the Serializable
interface. ReleaseContents
类下使用到的类也需要实现Serializable
接口,例如你的ReleaseContents
类里面有个属性是Version
类,那么这个Version
类也许实现Serializable
接口。
回到你的例子,很明显,在ReleaseContents
类有个属性是Bitmap
类,Bitmap
并没有实现Serializable
接口,而是实现了Parcelable
ReleaseContents
class has an attribute of the Bitmap
class, and Bitmap
does not implement Serializable< /code>interface, but implements the Parcelable
interface. 🎜reply0
ringa_lee2017-04-17 17:33:33
Use Android's serialization class instead of the traditional java serialization class
Parcelable this. Or use the Gson tool to convert the map into a String, then pass it and parse it into a map
黄舟2017-04-17 17:33:33
map
没有实现序列化的接口,无法实现序列化,可以尝试一下hashmap
,hashmap
原本就可以保存在bundle
中,也可像楼上一样使用parcelable
It is also faster to achieve this.