Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Class cast exception

Status
Not open for further replies.

Jefhandle

Technical User
Mar 9, 2005
69
DE
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];
??
Thanks for your help

 
You have to choose wether to use the package name or not, but is has to be consistent

Code:
com.projectA.MyDupplicateA myAObject = (com.projectA.MyDupplicateA) com.projectB.getBObjects()[0];

or

Code:
import com.projectA.MyDupplicateA;

MyDupplicateA myAObject = (MyDupplicateA) com.projectB.getBObjects()[0];

Cheers,
Dian
 
Thanks, but doe not work! ??
here are my class hirarchy:
MyDupplicateA extends probjectB.Objectx implments projectB.xxInterface
projectB.MyObjectB extends probjectB.Objectx implments projectB.xxInterface

Anay Idea??
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top