public class Common implements Serializable{
private static HashMap<Integer,List<LevelList>> levelListMap = new HashMap<>();
public static Map<Integer, List<LevelList>> getLevelListMap(Context context) {
File file = new File(context.getDir("data", MODE_PRIVATE), "map");
ObjectInputStream inputStream = null;
try {
inputStream = new ObjectInputStream(new FileInputStream(file));
levelListMap = (HashMap<Integer, List<LevelList>>) inputStream.readObject();
} catch (Exception e) {
e.printStackTrace();
}
return levelListMap;
} ...
}
我無法序列hashmap.I不斷得到java.io.NotSerializableException
爲 levelListMap = (HashMap<Integer, List<LevelList>>) inputStream.readObject();
無法序列是HashMap,java.io.NotSerializableException
public class LevelList implements Serializable{
public int id;
public String title;
public String imgurl;
public String songurl;
public String songtext;
boolean isFavourite;
public void release() {
}
public void setFavourite(boolean favourite) {
isFavourite = favourite;
}
public boolean isFavourite(){
return isFavourite;
}
}
請添加堆棧跟蹤。 – Sangharsh
序列化時,您必須得到完全相同的異常,並且您必須忽略它。不要這樣做。 – EJP