aspose file tools
The moose likes Java in General and the fly likes Class Cast exception? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Class Cast exception?" Watch "Class Cast exception?" New topic
Author

Class Cast exception?

Babloo Chaudhari
Greenhorn

Joined: May 02, 2005
Posts: 1
Hey, I have 2 java project one is main application project, and other is the worker project. I am using xsd as contract.now the common schema(xsd) resides in application project. In the worker project I have the response schema which has the common as include schema.

so when I compile both projects, using jaxb first, it creates the java classes for common schema in both application, as well as in worker project.

I have some common functionality, in the application project, which uses the java classes of jaxb compiled common schema. but when I invoke this functionality from worker project, it takes the input as java classes from application project, so I need to cast the jaxb compiled java classes from the worker project to jaxb compiled java classes of application project.

but at run time this cast always fails, with java.lang.ClassCastException.

I even tried to use, Class.cast(Object o) method, to perform the casting, but no luck

{no format}Please suggest me the ways of casting?{no format}
For eg:

List<com.abc.xyz.application.contributions.BusinessContactType> bConList = null;
if (cpReq.getBusinessContacts() != null
&& cpReq.getBusinessContacts().getBusinessContact() != null) {
bConList = (List<com.abc.xyz.application.contributions.BusinessContactType
><div class="jive-quote">) cpReq</div>
.getBusinessContacts().getBusinessContact();
}
if (bConList.size() > 0) {
busCode = ctwfUtils.addUpdBusinessContactDetails(wiidarr,
bConList, param);
}



in abocve code

cpReq.getBusinessContacts().getBusinessContact()

returns me the list of business contacts of type com.abc.xyz.worker.contributions.BusinessContactType & my function

ctwfUtils.addUpdBusinessContactDetails(wiidarr,bConList, param);

require the bCon list of com.abc.xyz.application.contributions.BusinessContactType.

While BusinessContactType is the common xml schema complex type. which is used in the request of worker xml schema. Jaxb compiler created the BusinessContactType
in appliccation as well as in the worker project.
xml
Always, {Code} bConList = (List<com.abc.xyz.application.contributions.BusinessContactType
) cpReq.getBusinessContacts().getBusinessContact();{code}
this casting fails.

I am not able to find any reasons.>
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3268

Hi there and welcome to Javaranch!

Could you please edit your post using the code buttons? It'll make it easier for us to read your question if the code is highlighted


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Class Cast exception?
 
Similar Threads
Cannot compile XSD using JAXB
dependency inject in web services
How to use Spring / DWR Revers Ajax functionality to display dynamic changes to table data
Bridge between REST & WS
jaxb xml parsing, null pointer for IDRef element