0

Possible Duplicate:
Java serialization - java.io.InvalidClassException local class incompatible

I have written a program that stores an Object (say A) as a file (say F). So when you run the program later you can load it and use its contents. So far so good. But today i decided to make a some changes to class A. I made a backup of the original (called it Aold). But the thing i realized too late, is that the information stored on F is very valuable to me. And ofcourse when i tried to load it as a new Object A it failed. Next i wrote a converter, that takes a file with an Aold object as its contents and turns it into a new A class (still with me?) next writes it back to disk. This, so that next time my program can load it directly. I renamed oldA to A again.

But the horror. the horror. I got this exception when i tried to load and A object from disk:

java.io.InvalidClassException: model.A; local class incompatible: stream classdesc serialVersionUID = -4621085703760431015, local class serialVersionUID = -3183461156231139807

Did i just messed up, and is the information lost? Or is there a solution?

Community
  • 1
  • 1
  • 1
    try using `serialVersionUID ` as `-4621085703760431015` in Aold. – Nandkumar Tekale Oct 16 '12 at 18:59
  • if i declare a public static long serialVersionUID = -462108570376043101 the compiler errors saying that this value is too large for a long. – user1751017 Oct 16 '12 at 19:01
  • did you check duplicate link? – Nandkumar Tekale Oct 16 '12 at 19:03
  • yes. Says i need to add the serialVersionUID to the class A: public static long serialVersionUID = -4621085703760431015L; but get the exact same exception – user1751017 Oct 16 '12 at 19:10
  • got this one: java.io.InvalidClassException: A; local class incompatible: stream classdesc serialVersionUID = -4621085703760431015, local class serialVersionUID = 2625576809510858943 at java.io.ObjectStreamClass.initNonProxy(Unknown Source) at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source) at java.io.ObjectInputStream.readClassDesc(Unknown Source) at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source) at java.io.ObjectInputStream.readObject0(Unknown Source) at java.io.ObjectInputStream.readObject(Unknown Source) – user1751017 Oct 16 '12 at 19:13
  • [x] Solved. the declaration of the serialVersionUID needed to be "final". It works now. Thanks. – user1751017 Oct 16 '12 at 19:17

0 Answers0