• 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

Invalid Class Exception

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

This is my first attempt at using serialization. I'm trying to be able to save an object that can later be 'loaded' in. However i get this error message when trying to deserialize:

java.io.InvalidClassException: SupplierInvoiceAllocationView; local class incompatible: stream classdesc serialVersionUID = -709346598771344625, local class serialVersionUID = 1302362001276124093;

My initial feeling is that because i'm trying to load the class SupplierInvoiceAllocationView from a different class is causing the problem. Is this the case? Any advice would be greatly appreciated!

Cheers.
 
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This has probably happened because you have changed (and compiled) the SupplierInvoiceAllocationView class since you saved that previous instance to disk. If you make certain changes to a class (e.g adding new fields) there will be a problem when you try to read older versions of that class, because those fields didn't exist when you saved the data.

In order to assist with these problems, a class has a serial version, called the serialVersionUID. You will get the InvalidClassException when you try to load an instance of a class that has a different serialVersionUID to the stored one.

There is a solution though. That error message is telling you that your saved class has the version -709346598771344625. Add this code to the top of your SupplierInvoiceAllocationView class and recompile it:

This will 'force' the local class to be 'compatible' with the saved class. The de-serialization will now work. However, bear in mind that any additional fields you added to SupplierInvoiceAllocationView will be given their default values (typically zero or null), which might need extra code to take care of straight after de-serialization.

You can find out more information about Serialization
here
[ August 16, 2005: Message edited by: Stuart Gray ]
 
Marcus Hathaway
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Stuart that's made me understand why it didn't work. It was actually not working aswell for another simpler reason but i couldn't see past that exception. Now working fine! Cheers!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic