Results 1 to 5 of 5
  1. #1
    henry123 is offline Member
    Join Date
    Feb 2011
    Posts
    22
    Rep Power
    0

    Default Class Cast exception

    Hi
    I have two Java Projects ProjectA, ProjectB
    ProjectA has a refrence to ProjectB and can call the Java classes from ProjectB.
    Now , I hava created in A, a Dupplicate of a Java class which exists in B and try to
    Cast the originally Object(exist in B) as follow but I get a class cast exception:
    com.projectA.MyDupplicateA myAObject = (MyDupplicateA)
    com.projectB.getBObjects()[0];
    ?
    Is that a class loader Problem?
    Is that possible avoid this cast exception without changing the desgin of ProjectA, f.i. removing MyDupplicateA and cast again with the same ObjectB from ProjectB)?
    Thanks for your help

  2. #2
    codesmuggler is offline Member
    Join Date
    Feb 2011
    Posts
    30
    Rep Power
    0

    Default

    Two classes with the same definitions but in two projects / jars will never be the same class. Remove one of them.

  3. #3
    henry123 is offline Member
    Join Date
    Feb 2011
    Posts
    22
    Rep Power
    0

    Default

    Hi
    Thanks, but, my MyDupplicateA extends the Same Objects and same Interface from ProjectB,as the MyDupplicateB extends and implements
    MyDupplicateA extends probjectB.Objectx implments projectB.xxInterface
    projectB.MyObjectB extends probjectB.Objectx implments projectB.xxInterface
    ??
    Last edited by henry123; 02-14-2011 at 09:05 AM.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,337
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by henry123 View Post
    Hi
    Thanks, but, my MyDupplicateA extends the Same Objects and same Interface from ProjectB,as the MyDupplicateB extends and implements
    MyDupplicateA extends probjectB.Objectx implments projectB.xxInterface
    projectB.MyObjectB extends probjectB.Objectx implments projectB.xxInterface
    ??
    The classes String and InputStream both extend class Object directly; that doesn't make them assignable to eachother.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    henry123 is offline Member
    Join Date
    Feb 2011
    Posts
    22
    Rep Power
    0

Similar Threads

  1. Need Help with Class Cast Exception
    By soxfan714 in forum New To Java
    Replies: 2
    Last Post: 11-03-2011, 04:33 PM
  2. Convert Vector to Generic Array Cast Exception
    By officialhopsof in forum New To Java
    Replies: 3
    Last Post: 01-04-2011, 03:49 AM
  3. Cast own class to FrameView
    By Luxpsycho in forum AWT / Swing
    Replies: 0
    Last Post: 07-16-2010, 10:13 AM
  4. Menu Type cast Exception
    By arulmozs in forum AWT / Swing
    Replies: 8
    Last Post: 11-02-2009, 10:34 PM
  5. class cast exception
    By venkatallu in forum New To Java
    Replies: 2
    Last Post: 09-02-2008, 09:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •