我只有第一次在 objStream.writeObject(myobj) 中得到 NotSerializableException。
myobj 内部包含一个对象列表。同样的 myobj,当它不是第一个时,可以很好地序列化。请问有什么想法吗?代码看起来有点像这样:
public class MyObj implements Serializable
{
private List<MyOtherObjects> objects;
};
for (myobj : myobjs) {
byteOutputStream = new ByteArrayOutputStream();
ObjectOutputStream objStream = new ObjectOutputStream(byteOutputStream);
objStream.writeObject (myobj);
objStream.flush();
objStream.close();
file.write(byteOutputStream.toByteArray());
...
堆栈跟踪:
DoCompute flush thread [XRXTransactionQueue-1-1402065645208--1569561033][1] where
[1] java.io.ObjectOutputStream.writeObject0 (ObjectOutputStream.java:1,156)
[2] java.io.ObjectOutputStream.defaultWriteFields (ObjectOutputStream.java:1,509)
[3] java.io.ObjectOutputStream.writeSerialData (ObjectOutputStream.java:1,474)
[4] java.io.ObjectOutputStream.writeOrdinaryObject (ObjectOutputStream.java:1,392)
[5] java.io.ObjectOutputStream.writeObject0 (ObjectOutputStream.java:1,150)
[6] java.io.ObjectOutputStream.writeObject (ObjectOutputStream.java:326)
[7] utils.DoCompute$FileHandler.flush (DoCompute.java:678)