• 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

updated object no longer loadable

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Daniel Gallant
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I added "private static final long serialVersionUID = 124960255546936769L;" to the new class, but now I get a new error:

cannot assign instance of icons_character_folio.CharacterRecord to field icons_character_folio.Power.ch of type icons_character_folio.CharacterRecord101 in instance of icons_character_folio.Healing

I get that error when I do this:

och = (CharacterRecord)in.readObject();

Any help is appreciated.
 
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
You'll need to use the same class names as well as the same serialVersionUID.
 
Daniel Gallant
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, so how do I load the old file saved with the original CharacterRecord object to convert it to the new object?

Again, thanks for your help.
 
Rob Spoor
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
If the only changes are the methods (i.e. you have the same field names, types and order), then the two classes are actually compatible. After all, the data of the class is the same. Simply use the same serialVersionUID, same class name, and as far as the (de)serialization process is concerned it's the same class.
 
Daniel Gallant
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
GAH!!! I feel so dumb!

I just used the new class and it worked.

I want to thank you all for your help!
 
Rob Spoor
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
You're welcome.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic