• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Class Cast exception?

Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
if (bConList.size() > 0) {
busCode = ctwfUtils.addUpdBusinessContactDetails(wiidarr,
bConList, param);

in abocve code


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.
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.>
Posts: 3285
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
this llama doesn't want your drama, he just wants this tiny ad for his mama
a bit of art, as a gift, that will fit in a stocking
    Bookmark Topic Watch Topic
  • New Topic