开发者

NotSerializableException problem

the following code throws the exception:

public class TestObject implements Serializable{

    private static final long serialVersionUID = 1L;

    public String value;

}


DbByteArrayOut开发者_StackOverflowputStream out = new DbByteArrayOutputStream();
ObjectOutputStream objOut = new ObjectOutputStream(out);
objOut.writeObject(objOut);
objOut.flush();
out.writeTo(file);
objOut.close();
out.close();

public class DbByteArrayOutputStream extends ByteArrayOutputStream {
    public DbByteArrayOutputStream() {
     super();
 }

 public synchronized void writeTo (RandomAccessFile file) throws IOException {
     byte[] data = super.buf;
     int l = super.size();
     file.writeInt(l);
     file.write(data, 0, l);
   }
}

Why? Thanks.


This is the problem:

ObjectOutputStream objOut = new ObjectOutputStream(out);
objOut.writeObject(objOut);

You're trying to serialize the stream to itself. That makes no sense at all. I suspect you meant:

objOut.writeObject(new TestObject());

or something similar.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜