Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

java.io.InvalidCastException  RSS feed

 
Pankaj kumar Dwivedi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello friends,
I am trying to read object from file and want to check equality of data member of reading object with another OBJECT. suppose there is a class Login with serialization with two data members username and password. object L1 is written object in file and object L2 is created in source code. and i want to equate both object. in my programm there is a error java.io.InvalidCastException stream classdesc serialversion id of both objects.
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Pankaj kumar Dwivedi:
java.io.InvalidCastException stream classdesc serialversion id


This sounds like you serialized an object, changed the class and then tried to unserialize the no longer matching object.
It is really difficult to tell without you providing us with a test case that replicates the problem.
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Firstly, it is an InvalidClassException and not InvalidCastException.
This is what the javadocs say:

Thrown when the Serialization runtime detects one of the following problems with a Class.

* 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

Does these reasons sound familiar

It will be helpful if you can provide the stacktrace.
P.S.: While asking questions, you can be a little more elaborate to help people help you better! Here are a few guidelines.
[ November 27, 2007: Message edited by: Nitesh Kant ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!