local class incompatible: stream classdesc

Discussion in 'Java' started by babz, Oct 13, 2006.

  1. babz

    babz Guest

    Hi everyone,

    I am using eclipse IDE and i have two different projects A and B. I
    serialize an object that belongs to project B and deserialize it later.
    But I am doing this serialization/deserilization in project A.

    I have two ways in project A to use the classes of project B.

    OPTION 1: create a jar file of classes of project B and add it as an
    external jar to project A.
    OPTION 2: add project B to the build path of project A. (In this way i
    have an access to the source code of project B as well. So changing
    something in project B will not require me to create its jar file again
    and refresh project A).

    Then I have another application, call it C, that uses the jar files of
    projects A and B. If I use option 1 and then create project A's jar and
    project B's jar and give it to the application C, the
    serialization/deserialization works. but if i use option 2 in eclipse
    and build the respective jar files and try running the application with
    these jar files, I get the following exception:

    java.io.InvalidClassException:
    com.cambridgedocs.jpdf.pdo.fonts.PdoTrueTypeFont; local class
    incompatible: stream classdesc serialVersionUID = -3611946473283033478,
    local class serialVersionUID = 387207963493818039
    at java.io_ObjectStreamClass.initNonProxy(ObjectStreamClass.java:463)
    at
    java.io_ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1521)
    at
    java.io_ObjectInputStream.readClassDesc(ObjectInputStream.java:1435)
    at
    java.io_ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1626)
    at java.io_ObjectInputStream.readObject0(ObjectInputStream.java:1274)
    at java.io_ObjectInputStream.readObject(ObjectInputStream.java:324)
    at

    I want it to run it successfully through both ways

    Can someone help??

    Thanks,

    Babz
    babz, Oct 13, 2006
    #1
    1. Advertising

  2. babz

    Nigel Wade Guest

    babz wrote:

    > Hi everyone,
    >
    > I am using eclipse IDE and i have two different projects A and B. I
    > serialize an object that belongs to project B and deserialize it later.
    > But I am doing this serialization/deserilization in project A.
    >
    > I have two ways in project A to use the classes of project B.
    >
    > OPTION 1: create a jar file of classes of project B and add it as an
    > external jar to project A.
    > OPTION 2: add project B to the build path of project A. (In this way i
    > have an access to the source code of project B as well. So changing
    > something in project B will not require me to create its jar file again
    > and refresh project A).
    >
    > Then I have another application, call it C, that uses the jar files of
    > projects A and B. If I use option 1 and then create project A's jar and
    > project B's jar and give it to the application C, the
    > serialization/deserialization works. but if i use option 2 in eclipse
    > and build the respective jar files and try running the application with
    > these jar files, I get the following exception:
    >
    > java.io.InvalidClassException:
    > com.cambridgedocs.jpdf.pdo.fonts.PdoTrueTypeFont; local class
    > incompatible: stream classdesc serialVersionUID = -3611946473283033478,
    > local class serialVersionUID = 387207963493818039
    > at java.io_ObjectStreamClass.initNonProxy(ObjectStreamClass.java:463)
    > at
    > java.io_ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1521)
    > at
    > java.io_ObjectInputStream.readClassDesc(ObjectInputStream.java:1435)
    > at
    > java.io_ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1626)
    > at java.io_ObjectInputStream.readObject0(ObjectInputStream.java:1274)
    > at java.io_ObjectInputStream.readObject(ObjectInputStream.java:324)
    > at
    >
    > I want it to run it successfully through both ways
    >
    > Can someone help??
    >
    > Thanks,
    >
    > Babz


    OPTION 1 is the correct way to do things. Duplicating class files is not the way
    to go. OPTION 2 has created two .class files for the same .java source file,
    and each of them has a different UID.

    However, you can make it work if you define a serialVersionUID for each class
    that you wish to serialize. In fact Eclipse now warns you if you don't do this.

    Just add the following at the start of each class which will be serialized:

    private static final long serialVersionUID = <largenumber>L;

    where <largenumber> is an arbitrary integer which is unique to each class. You
    should do this for *every* class which is serialized, and that means classes
    contained in other classes, including anonymous inner classes.

    --
    Nigel Wade, System Administrator, Space Plasma Physics Group,
    University of Leicester, Leicester, LE1 7RH, UK
    E-mail :
    Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555
    Nigel Wade, Oct 13, 2006
    #2
    1. Advertising

  3. babz

    babz Guest

    Thnks Nigel. It works for me :)
    Nigel Wade wrote:
    > babz wrote:
    >
    > > Hi everyone,
    > >
    > > I am using eclipse IDE and i have two different projects A and B. I
    > > serialize an object that belongs to project B and deserialize it later.
    > > But I am doing this serialization/deserilization in project A.
    > >
    > > I have two ways in project A to use the classes of project B.
    > >
    > > OPTION 1: create a jar file of classes of project B and add it as an
    > > external jar to project A.
    > > OPTION 2: add project B to the build path of project A. (In this way i
    > > have an access to the source code of project B as well. So changing
    > > something in project B will not require me to create its jar file again
    > > and refresh project A).
    > >
    > > Then I have another application, call it C, that uses the jar files of
    > > projects A and B. If I use option 1 and then create project A's jar and
    > > project B's jar and give it to the application C, the
    > > serialization/deserialization works. but if i use option 2 in eclipse
    > > and build the respective jar files and try running the application with
    > > these jar files, I get the following exception:
    > >
    > > java.io.InvalidClassException:
    > > com.cambridgedocs.jpdf.pdo.fonts.PdoTrueTypeFont; local class
    > > incompatible: stream classdesc serialVersionUID = -3611946473283033478,
    > > local class serialVersionUID = 387207963493818039
    > > at java.io_ObjectStreamClass.initNonProxy(ObjectStreamClass.java:463)
    > > at
    > > java.io_ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1521)
    > > at
    > > java.io_ObjectInputStream.readClassDesc(ObjectInputStream.java:1435)
    > > at
    > > java.io_ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1626)
    > > at java.io_ObjectInputStream.readObject0(ObjectInputStream.java:1274)
    > > at java.io_ObjectInputStream.readObject(ObjectInputStream.java:324)
    > > at
    > >
    > > I want it to run it successfully through both ways
    > >
    > > Can someone help??
    > >
    > > Thanks,
    > >
    > > Babz

    >
    > OPTION 1 is the correct way to do things. Duplicating class files is not the way
    > to go. OPTION 2 has created two .class files for the same .java source file,
    > and each of them has a different UID.
    >
    > However, you can make it work if you define a serialVersionUID for each class
    > that you wish to serialize. In fact Eclipse now warns you if you don't do this.
    >
    > Just add the following at the start of each class which will be serialized:
    >
    > private static final long serialVersionUID = <largenumber>L;
    >
    > where <largenumber> is an arbitrary integer which is unique to each class. You
    > should do this for *every* class which is serialized, and that means classes
    > contained in other classes, including anonymous inner classes.
    >
    > --
    > Nigel Wade, System Administrator, Space Plasma Physics Group,
    > University of Leicester, Leicester, LE1 7RH, UK
    > E-mail :
    > Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555
    babz, Oct 16, 2006
    #3
  4. babz

    Krishna Kumar Chourasiya

    Joined:
    Feb 25, 2013
    Messages:
    1
    Location:
    India
    Caused by: java.io.InvalidClassException: com.XXX; local

    Hi Nigel Wade,

    I tried with the solution you have provided in this below mail. But it doesn't work for me. I am still getting same exception.

    Any help greatly appreciated.

    Thanks in advance

    Regards
    Krishna
    Krishna Kumar Chourasiya, Feb 25, 2013
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. amine
    Replies:
    0
    Views:
    368
    amine
    Oct 19, 2003
  2. E11
    Replies:
    1
    Views:
    4,707
    Thomas Weidenfeller
    Oct 12, 2005
  3. cc
    Replies:
    4
    Views:
    14,552
    puzz...
    Oct 25, 2005
  4. Eric
    Replies:
    0
    Views:
    442
  5. Guest
    Replies:
    1
    Views:
    194
    Jim Blizzard [MSFT]
    Oct 23, 2003
Loading...

Share This Page