Scott Deutsch
Scott Deutsch

Reputation: 657

Java weird run-time error with ObjectInputStream

I am getting this error all of the sudden. It was working before until today. I wonder if java updated or something and killed this from working.

Error I am getting:

java.io.InvalidClassException: javax.swing.JComponent; local class incompatible: stream classdesc serialVersionUID = -1030230214076481435, local class serialVersionUID = -2790168081368361182

This happens when I do the following

....
ObjectInputStream open = new ObjectInputStream(openFile);
Object obj =  open.readObject(); <--- dies here

What should I try to fix this issue. I would love to be able to open my files again.

Thanks.

Upvotes: 1

Views: 180

Answers (3)

basiljames
basiljames

Reputation: 4847

It would be because you created the file openFile in a jdk/jre version different from the one you are running now. So the JComponent class' serialVersionid is different.

Try running your application with the previous jre (cannot say if it old or new).

Upvotes: 3

Stephen C
Stephen C

Reputation: 718708

Yes. I suspect you have switched versions of Java. Note that the javadoc for JComponent says this:

"Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeans has been added to the java.beans package. Please see XMLEncoder."


What should I try to fix this issue. I would love to be able to open my files again.

There is not much you can so apart from switching back to the JRE / JDK you were using previously. The long-term fix is to reengineer your application to store the state some other way.

Upvotes: 2

turtledove
turtledove

Reputation: 25904

Change your clsas serialVersionUID -2790168081368361182 to -1030230214076481435, and have a try.

Upvotes: 0

Related Questions