• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

Getting an exception(Serialization)

 
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Put the moon back where you found it! We need it for tides and poetry and stuff. Like this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!