• Post Reply Bookmark Topic Watch Topic
  • New Topic

Class Cast exception after lookup( "RequestDispatcherBean")

 
Ramneek Handa
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting class cast exception while typecasting the reference to the home class after looking up the Request Dispatcher
I am able to look up but it gives classcastexception while typecasting.
This is the peace of code :
Context ctx=getContext();
System.out.println("Context is "+ctx);
Object objref = ctx.lookup ("RequestDispatcherBean");
System.out.println("objeref is "+objref);
home = (RequestDispatcherHome) objref;
the output of above code comes as
Context is javax.naming.InitialContext@98b
objeref is RequestDispatcherBean EJBHome
java.lang.ClassCastException: RequestDispatcherHome_StatelessSessionHomeWrapper7
com.indus.banner.integration.controller.RequestDispatcherHome com.indus.banner.components.account.Account
ManagerBean.getRequestDispatcherHome()
I don't understand when it is printing objeref is RequestDispatcherBean EJBHome
then why I am not able to cast it in the next line. I have tried with narrowing it down but it does not work even.
Any suggestions???
[ June 03, 2003: Message edited by: Ramneek Handa ]
 
Kishorekhan Kumar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
y don't u typecast to "Object" in the third line of the code and try.
 
Ramneek Handa
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
typecast to "Object" is not making any difference.
 
Ramneek Handa
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can somebody put a light on the output of
System.out.println("objeref is "+objref);
which is coming as
objeref is RequestDispatcherBean EJBHome
Why it is showing RequestDispatcherBean as class name instead of RequestDispatcherHome which is the name of Home class.
Pl someone tell me. FYI I am using OC4J
-thanks
 
Tausif Khanooni
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi..,
Just try out this:
Context ctx = new InitialContext();
Object objref = ctx.lookup("RequestDispatcherBean");
home = (RequestDispatcherHome)PortableRemoteObject.narrow(objref,RequestDispatcherHome.class);

hope it will solve ur problem
cheers
Tausif
 
Bhiku Mhatre
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just make sure if this is not a classloader problem. Make sure that the home interface your client is trying to cast to is loaded at a higher level such as .EAR or even system classpath level.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!