• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Error while deserializing an object.

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am getting following exception, while using readObject() method:

DeSerializeDate.java:11: unreported exception java.lang.ClassNotFoundException;
must be caught or declared to be thrown
d=(Date) s.readObject();
^


Please give solution for it...
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Catch or re-throw ClassNotFoundException.

I'll explain the reason why ObjectInputStream.readObject() can throw this exception with this little example:

You have an instance of class X. You serialize this instance to a file, and then give the file to someone else. This other person does not have class X on his class path. He then tries to de-serialize the file. The de-serialization tries to find class X but it can't find it. It doesn't know what to do so it throws an exception. It could have thrown an IOException but a ClassNotFoundException makes it clearer what the exact problem is - a missing class file.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic