ObjectOutputStream
Hi frends, i've a problem....i have to send one Vector that includes two Vector and one int value.
I send this Vector with the ObjectOutputStream out
publicvoid send(Object a){
try{
out.writeObject(a);
}catch (IOException ex){
ex.printStackTrace();
}
}
but if i do this operation, i receive always the first Vector and it never changes!!
Can you help me?....please i have to deliver the project tomorrow!!
Thanks
If you do this:
send(v);
...
v.add(somethingElse); //for example
send(v);
The result of the send call is not what you expect.
On the other end of the object stream, you will discover this:
Object v1 = in.readObject(); //matching first call to send(v);
Object v2 = in.readObject(); //matching second call to send(v)
if (v1 == v2) //true!!
That's the way object streams work, they preserve reference graphs.
To get around this:
1. You can create a new vector each time (and consider its contents, too!), or
2. Call method [url=http://java.sun.com/j2se/1.5.0/docs/api/java/io/ObjectOutputStream.html#reset()]reset[/url] on the object output stream. This may not be what you
want in some cases --
you may want to preserve the reference graph -- so think this over.
Thanks for the assistance....but now i've another problem.
I have to send one object which belong to one class created from me....if i send it with the function out.write(object_of_my_class)
(obviusly out is one ObjectOutputStream) the program makes one errorof the kind .NotSerializableException....how i can solve this problem....
Thamks
> the program makes one
> errorof the kind .NotSerializableException....how i
> can solve this problem....
> Thamks
Make the object serializable (implementing the Serializable or Externalizable interfaces)
(oops too slow)
Message was edited by:
Ruly-o_O