| Author |
Getting an exception(Serialization)
|
Amit Batra
Ranch Hand
Joined: Mar 04, 2006
Posts: 361
|
|
The code below is from the k&B. Why am I getting an exception when I deserialize?. Ive run through this code but still cant see what im doing wrong. Please help.
|
 |
Gowher Naik
Ranch Hand
Joined: Feb 07, 2005
Posts: 643
|
|
Above code serilize and deserilize a transient variable. comment and uncomment private writeObject and readObject methods and see the output. I hope it will help You.
|
 |
Patrick Patel
Greenhorn
Joined: Aug 25, 2006
Posts: 9
|
|
|
Transient variables are not Serializable. If transient variable is a primitive and you try to deserialize it, java will initialize the primitive with the default value, for an Object it will be null.
|
 |
Burkhard Hassel
Ranch Hand
Joined: Aug 25, 2006
Posts: 1274
|
|
G'day mates! Three errors, the wrong version is outcommented: // -->private void WriteObject(ObjectOutputStream os) throws IOException { private void writeObject(ObjectOutputStream os) throws IOException {try { //private void ReadObject(ObjectInputStream is) throws IOException, private void readObject(ObjectInputStream is) throws IOException,ClassNotFoundException { this method names must be lower case, and the third in the constructor: public Dog(Collar collar, int size) { theCollar = collar; //size = dogSize; dogSize=size; } just the other way round. Yours, Bu.
|
all events occur in real time
|
 |
 |
|
|
subject: Getting an exception(Serialization)
|
|
|