在序列化我的对象时,它是一个自定义类,包含各种 ArrayList,我经常会遇到并发 Mod 异常。显然,一个或多个数组列表正在抛出这个。但我不知道在哪里,或者如何解决它。实现迭代器将是我的第一个想法,但是如何进行序列化呢?
这是我的序列化代码:enter code here
try{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
ObjectOutput out = new ObjectOutputStream(bos);
out.writeObject(TGame);
// Get the bytes of the serialized object
byte[] buf = bos.toByteArray();
File sdCard = Environment.getExternalStorageDirectory();
File dir = new File (sdCard.getAbsolutePath() + "/game_folder");
dir.mkdirs();
File file = new File(dir, "serializationtest");
FileOutputStream fos = new FileOutputStream(file);
//this.openFileOutput(filename, Context.MODE_PRIVATE);
fos.write(buf);
fos.close();
} catch(IOException ioe) {
Log.e("serializeObject", "error", ioe);
}catch(StackOverflowError e){
//do something
}
File f =this.getDir(filename, 0);
Log.v("FILE SAVED",f.getName());
}catch(ConcurrentModificationException e){
//do something
}
}