Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > InvalidClassException!

Reply
Thread Tools

InvalidClassException!

 
 
Raga
Guest
Posts: n/a
 
      09-26-2006
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.

 
Reply With Quote
 
 
 
 
opalpa@gmail.com opalinski from opalpaweb
Guest
Posts: n/a
 
      09-26-2006

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
http://www.velocityreviews.com/forums/(E-Mail Removed)
http://www.geocities.com/opalpaweb/




Raga wrote:
> 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.


 
Reply With Quote
 
 
 
 
Raga
Guest
Posts: n/a
 
      09-26-2006
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.


(E-Mail Removed) opalinski from opalpaweb wrote:
> 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
> (E-Mail Removed)
> http://www.geocities.com/opalpaweb/
>
>
>
>
> Raga wrote:
> > 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.


 
Reply With Quote
 
Raga
Guest
Posts: n/a
 
      09-26-2006
sorry,...just noticed. The class implements Serializable. Now what can
I do to solve the problem?

Thanks.


Raga wrote:
> 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.
>
>
> (E-Mail Removed) opalinski from opalpaweb wrote:
> > 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
> > (E-Mail Removed)
> > http://www.geocities.com/opalpaweb/
> >
> >
> >
> >
> > Raga wrote:
> > > 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.


 
Reply With Quote
 
opalpa@gmail.com opalinski from opalpaweb
Guest
Posts: n/a
 
      09-26-2006

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
(E-Mail Removed)
http://www.geocities.com/opalpaweb/

 
Reply With Quote
 
Andrea Desole
Guest
Posts: n/a
 
      09-26-2006
(E-Mail Removed) opalinski from opalpaweb wrote:
> 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/gu...doc6.html#4100

You just have to remember to change it when you change the
implementation
 
Reply With Quote
 
Tim Hallwyl
Guest
Posts: n/a
 
      09-26-2006
Raga wrote:
> 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
 
Reply With Quote
 
Raga
Guest
Posts: n/a
 
      09-27-2006
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.


Tim Hallwyl wrote:
> Raga wrote:
> > 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


 
Reply With Quote
 
Andrea Desole
Guest
Posts: n/a
 
      09-27-2006
Raga wrote:
> 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!


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.
 
Reply With Quote
 
Tor Iver Wilhelmsen
Guest
Posts: n/a
 
      09-27-2006
Andrea Desole <(E-Mail Removed)> writes:

> 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).
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments