Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Java in General and the fly likes InvalidClassException: Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "InvalidClassException: " Watch "InvalidClassException: " New topic
Author

InvalidClassException:

Hemant Khurana
Greenhorn

Joined: Jan 11, 2007
Posts: 27
I am getting a java.io.InvalidClassException: exception at runtime in my application.

The class compiles fine but when i run the application i get this exception.

I have checked the API docs and there are reasons for this to happen

The serial version of the class does not match that of the class descriptor read from the stream
The class contains unknown datatypes
The class does not have an accessible no-arg constructor

I dont understant the first one and the rest 2 dont apply to my case

I am getting a exception when i am changing data types of certain class memeber variables from long to double but then double should not a unknown data type
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38472
    
  23
Do you mean you are casting a double or a Double? Read this.

You should have no difficulty casting longs to doubles and vice versa but you ought not to be able to cast Longs and Doubles.

CR
Bupjae Lee
Ranch Hand

Joined: May 14, 2007
Posts: 107
The serial version of the class does not match that of the class descriptor read from the stream

This means that it has same class name between what you do serialize (this means ObjectOutputStream.writeObject()) and what you deserialize (this means ObjectInputStream.readObject()), but it isn't same class.

In java serialize system, every serializable class has its own ID code that called 'serialVersionUID', and it is recommended every serializable class declared that value such as:


If you don't include that, java creates ID according with what methods and fields are declared in that class. So unless you declared ID, that may or may not be changed when you change class.
You can see current ID such as:


serialver utility is in JDK/bin directory.
[ May 15, 2007: Message edited by: Bupjae Lee ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: InvalidClassException: