Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2006

Tip: Looking for answers? Try searching our database.

InvalidClassException!

Thread view: 
Raga - 26 Sep 2006 15:17 GMT
Hi,

When executing a class am getting this exception:

java.io.InvalidClassException: package1.Queries; local class
incompatible: stream classdesc serialVersionUID = 7965341194343831580,
local class serialVersionUID = -3010695744043114199

Any idea how to solve this? In fact, I didnt even change anything in
this class before I got this exception.

Thanks.
opalpa@gmail.com opalinski from opalpaweb - 26 Sep 2006 15:25 GMT
The java virtual machine is indicating that it believes there are two
versions of a class in play at the same time.

Does the class read saved objects (saved by serialization)?
Does the class use RMI?

Opalinski
opalpa@gmail.com
http://www.geocities.com/opalpaweb/

> Hi,
>
[quoted text clipped - 8 lines]
>
> Thanks.
Raga - 26 Sep 2006 15:32 GMT
O OK. Thanks a lot. But how do I make the JVM understand that there is
only one version of the class?

Nope, the class doesn't use RMI nor does it has to do anything with
serialized objects. It just manipulates some hashtables.

Thanks.

> The java virtual machine is indicating that it believes there are two
> versions of a class in play at the same time.
[quoted text clipped - 18 lines]
> >
> > Thanks.
Raga - 26 Sep 2006 15:35 GMT
sorry,...just noticed. The class implements Serializable. Now what can
I do to solve the problem?

Thanks.

> O OK. Thanks a lot. But how do I make the JVM understand that there is
> only one version of the class?
[quoted text clipped - 26 lines]
> > >
> > > Thanks.
opalpa@gmail.com opalinski from opalpaweb - 26 Sep 2006 15:42 GMT
Find out where serialized objects are being read in.  The objects being
read in have a different class definition than the one in the JVM.

I suspect that's the case.

Opalinski
opalpa@gmail.com
http://www.geocities.com/opalpaweb/
Andrea Desole - 26 Sep 2006 16:00 GMT
> Find out where serialized objects are being read in.  The objects being
> read in have a different class definition than the one in the JVM.

The problem can also be caused by two different compilers.
The best option is to set the serialVersionUID in the class:

http://java.sun.com/j2se/1.3/docs/guide/serialization/spec/class.doc6.html#4100

You just have to remember to change it when you change the
implementation :-)
Tim Hallwyl - 26 Sep 2006 17:40 GMT
> When executing a class am getting this exception:
>
> java.io.InvalidClassException: package1.Queries; local class
> incompatible: stream classdesc serialVersionUID = 7965341194343831580,
> local class serialVersionUID = -3010695744043114199

Are you serializing the class? You can declare your own serialVersionUID
to avoid conflicts between recompiled versions. Just add

private static final long serialVersionUID = 1;

to your serializable classes. ...and recompile everything.

--tim
Raga - 27 Sep 2006 10:06 GMT
Hi,

Thanks to all of you for your valuable inputs!

I got it fixed. The exception msg had a serialVersionUID in it. I used
it as the serialVersionUID of the class by specifying the foll. line in
the class:

static final long serialVersionUID = -3010695744043014199L;

& it worked! :)

Thanks.

> > When executing a class am getting this exception:
> >
[quoted text clipped - 10 lines]
>
> --tim
Andrea Desole - 27 Sep 2006 10:38 GMT
> Hi,
>
[quoted text clipped - 7 lines]
>
> & it worked! :)

Although this is a good solution, maybe

static final long serialVersionUID = 1L;

would be better :-)
The meaning of serialVersionUID, by the way, is that you are able to
identify different versions. You should think of a numbering convention.
Just using random numbers might give you a problem.
Tor Iver Wilhelmsen - 27 Sep 2006 18:07 GMT
> The meaning of serialVersionUID, by the way, is that you are able to
> identify different versions. You should think of a numbering
> convention. Just using random numbers might give you a problem.

Well, "identify" as in "get an annoying exception instead of the
actual data". So adding serialVersionUID becomes a necessary nuisance.

A useful versioning field would be instance data, and you could test
on it in redObject() and/or writeObject() and act accordingly (e.g. by
"upgrading" the data to ra new version before passing it on).


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.