• Post Reply Bookmark Topic Watch Topic
  • New Topic

Invalid Class Exception

 
Marcus Hathaway
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • 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.
 
Stuart Gray
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
  • 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
  • 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!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!