• 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 ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

ClassCastException when calling findBy method

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
We are having a peculiar problem. When we call the findBy method. It returns an enum. After typecasting to the right object, we get a ClassCastException when doing an enum.nextelement().
Please help us.
Regards
Srinivas

The code snippet and the error is given below.

Code snippet
=============================================================================================================================
Enumeration itemsEnum = myItemsEnumeration;
HashMap colorItemMap = new HashMap();
ArrayList distributionLotList = new ArrayList();
long quanityToAllocate = 0;
while (itemsEnum.hasMoreElements()) {
System.out.println("Before line 345...");
ItemInformation itemInfo = (ItemInformation) itemsEnum.nextElement();
ItemC itemObj = new ItemC();
itemObj
.initItem_withClassCode_vendorCode_styleCode_colorCode_sizeCode_prepackCode(
itemInfo.getClassCode(),
itemInfo.getVendorCode(),
itemInfo.getStyleCode(),
itemInfo.getColorCode(),
0,
null);
if (colorItemMap.containsKey(itemObj)) {
((Vector) colorItemMap.get(itemObj)).add(itemInfo);
} else {
Vector colorVector = new Vector();
colorVector.add(itemInfo);
colorItemMap.put(itemObj, colorVector);
// contains a list of vectors and the vectors contain same type of Colors.
}
}

=============================================================================================================================
java.lang.ClassCastException: org.omg.stub.javax.ejb._EJBObject_Stub
at com.i3j.prodapt.group.AllocatorC.buildComponent(AllocatorC.java:345)
at com.i3j.prodapt.group.AllocatorC.doAllocation_ForAllocationSessionIndex_storeWeightSessionIndex(AllocatorC.java:552)
at allocator_jsp_7._jspService(allocator_jsp_7.java:90)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:139)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.runtime.JspServlet$JspServletWrapper.service(JspServlet.java:286)
at org.apache.jasper.runtime.JspServlet.serviceJspFile(JspServlet.java:415)
at org.apache.jasper.runtime.JspServlet.service(JspServlet.java:544)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.ibm.servlet.engine.webapp.StrictServletInstance.doService(ServletManager.java:827)
at com.ibm.servlet.engine.webapp.StrictLifecycleServlet._service(StrictLifecycleServlet.java:159)
at com.ibm.servlet.engine.webapp.IdleServletState.service(StrictLifecycleServlet.java:286)
at com.ibm.servlet.engine.webapp.StrictLifecycleServlet.service(StrictLifecycleServlet.java:106)
at com.ibm.servlet.engine.webapp.ServletInstance.service(ServletManager.java:472)
at com.ibm.servlet.engine.webapp.ValidServletReferenceState.dispatch(ServletManager.java:1012)
at com.ibm.servlet.engine.webapp.ServletInstanceReference.dispatch(ServletManager.java:913)
at com.ibm.servlet.engine.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:499)
at com.ibm.servlet.engine.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:278)
at com.ibm.servlet.engine.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:105)
at com.ibm.servlet.engine.srt.WebAppInvoker.doForward(WebAppInvoker.java:67)
at com.ibm.servlet.engine.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:123)
at com.ibm.servlet.engine.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:67)
at com.ibm.servlet.engine.invocation.CacheableInvocationContext.invoke(CacheableInvocationContext.java:106)
at com.ibm.servlet.engine.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:125)
at com.ibm.servlet.engine.oselistener.OSEListenerDispatcher.service(OSEListener.java:315)
at com.ibm.servlet.engine.http11.HttpConnection.handleRequest(HttpConnection.java:60)
at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:313)
at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:242)
at com.ibm.ws.util.CachedThread.run(ThreadPool.java:122)
com.i3j.prodapt.AllocationException: In Color loop buildComponent() java.lang.ClassCastException: org.omg.stub.javax.ejb._EJBObject_Stub
at com.i3j.prodapt.group.AllocatorC.buildComponent(AllocatorC.java:424)
at com.i3j.prodapt.group.AllocatorC.doAllocation_ForAllocationSessionIndex_storeWeightSessionIndex(AllocatorC.java:552)
at allocator_jsp_7._jspService(allocator_jsp_7.java:90)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:139)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.runtime.JspServlet$JspServletWrapper.service(JspServlet.java:286)
at org.apache.jasper.runtime.JspServlet.serviceJspFile(JspServlet.java:415)
at org.apache.jasper.runtime.JspServlet.service(JspServlet.java:544)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.ibm.servlet.engine.webapp.StrictServletInstance.doService(ServletManager.java:827)
at com.ibm.servlet.engine.webapp.StrictLifecycleServlet._service(StrictLifecycleServlet.java:159)
at com.ibm.servlet.engine.webapp.IdleServletState.service(StrictLifecycleServlet.java:286)
at com.ibm.servlet.engine.webapp.StrictLifecycleServlet.service(StrictLifecycleServlet.java:106)
at com.ibm.servlet.engine.webapp.ServletInstance.service(ServletManager.java:472)
at com.ibm.servlet.engine.webapp.ValidServletReferenceState.dispatch(ServletManager.java:1012)
at com.ibm.servlet.engine.webapp.ServletInstanceReference.dispatch(ServletManager.java:913)
at com.ibm.servlet.engine.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:499)
at com.ibm.servlet.engine.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:278)
at com.ibm.servlet.engine.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:105)
at com.ibm.servlet.engine.srt.WebAppInvoker.doForward(WebAppInvoker.java:67)
at com.ibm.servlet.engine.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:123)
at com.ibm.servlet.engine.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:67)
at com.ibm.servlet.engine.invocation.CacheableInvocationContext.invoke(CacheableInvocationContext.java:106)
at com.ibm.servlet.engine.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:125)
at com.ibm.servlet.engine.oselistener.OSEListenerDispatcher.service(OSEListener.java:315)
at com.ibm.servlet.engine.http11.HttpConnection.handleRequest(HttpConnection.java:60)
at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:313)
at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:242)
at com.ibm.ws.util.CachedThread.run(ThreadPool.java:122)
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do a PortableRemoteObject.narrow() on the objects returned back from the Enumeration prior to the cast. That will fix your problem.
Kyle
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I am also getting ClassCastException
Error :
java.lang.ClassCastException: org.omg.stub.javax.ejb._EJBObject_Stub
--------------------------------------------------
My code:
Context con = new InitialContext();
Object oHeader=con.lookup("UsersHome");
System.out.println("After Looked up");
java.math.BigDecimal attrFilterID = new java.math.BigDecimal("1140");
com.attrdefault.UsersHome home=(com.attrdefault.UsersHome)PortableRemoteObject.narrow(oHeader,UsersHome.class);
System.out.println(">>>>>>>>>>>>>>>>>>>>>>> got home :");
java.util.Enumeration enAccount = home.findUsersByAft_attr_filter(attrFilterID);
System.out.println(">>>>>>>>>>>>>>>>>>>>>>> got remote :");
System.out.println(">>>>>>>>>>>>>>>>>>>>>>> enum :"+(enAccount == null));
System.out.println(">>>>>>>>>>>>>>>>>>>>>>> enum hasmoreelements:"+(enAccount.hasMoreElements()));
if((enAccount.hasMoreElements()))
{
System.out.println(">>>>>>>>>>>>>>>>>>>>>>> Object Found :");
//Object o=enAccount.nextElement();
//System.out.println(">>>>>>>>>>>>>>>>>>>>>>> Class Name :"+o.getClass().getName());
//com.attrdefault.Users u = (com.attrdefault.Users)o;
com.attrdefault.Users u = (com.attrdefault.Users)PortableRemoteObject.narrow(enAccount.nextElement(),com.attrdefault.Users.class);
System.out.println(">>>>>>>>>>>>>>>>>>>>>>> User Name :"+u.getUser_name());

}
--------------------------------------------------
Eventhough I did PortableRemoteObject.narrow()
It is givving the Error.
Kyle pl help me.
regards
venkat
reply
    Bookmark Topic Watch Topic
  • New Topic