Daniel Gallant wrote:Hi!
I have a program that is currently being used to create characters for a game. Recently, in order to fix a bug, I had to modify the character object (I added two methods). Now I can't load the old saved characters. My solution was to rename the original object from CharacterRecord to ChararacterRecord100. I tried loading the original object using ChararacterRecord100, but I get an error:
icons_character_folio.CharacterRecord; local class incompatible: stream classdesc serialVersionUID = 124960255546936769, local class serialVersionUID = 124960255546936770
Can anyone make a suggestion on how I can get around this issue?
Thanks for your help!
I assume that you saved the character objects using serialization? By default
Java calculates a unique (well semi unique) version-identifier (serialVersionUID) for each class based on its fields etc.
Well, you can read about it here:
http://java.sun.com/j2se/1.5.0/docs/api/java/io/Serializable.html
In short, in order to de-serialize a object, the version-identifier of the stream of the soon-to-be-object (ie the ones you saved before) must match the version-identifier of the class as it is today. But since you have modified the class this fails. The way around this is to specifically set the version-id to the same value as was calculated to the old version of the class (ie the first serialVersionUID in the error message).
So add this field to your class and it should probably solve this problem:
private static final long serialVersionUID = 124960255546936769L;
Hope this helps.
/Jimi