• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java.lang.ClassCastException

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have deployed the web application sucessfully in j2ee application server.When i run this application i am getting following errors:
java.lang.ClassCastException at com.sun.corba.ee.internal.javax.rmi.PortableRemoteObject.narrow()
on this code
Context ic = new InitialContext();
java.lang.Object objref = ic.lookup("java:comp/env/ejb/Category");
catHome = (CategoryHome) PortableRemoteObject.narrow(objref,ejbBeans.CategoryHome.class);
I have been stuck to this for last 4 days.I have searched from net but do not get any clue.
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The handle that you are trying to cast is the home interface, instead try to cast the remote interface.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You must cast it to home interface according to J2EE spec (I tried the remote thing for the heck of it). It just doesn't work. So far I only know one solution: do not use J2EE!
 
Ilya Dorfman
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was wrong. I solved it by generating stubs for the EJB home. Right-click on the home interface, goto Properties->Build->VisiBroker->Generate IIOP.
 
rohit aggarwal
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Dorfman,
i could not able to get you. what are stubs.please clearly explain me step wise.
I am very desperate to solve it.
 
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Rohit,
The reason you are getting the classcast exception is because the jar file is not on the class path of
your client application.

When you are deployed the application , by clicking on the
"Deploy application" menuitem, did you click on the check box which
said "Return Client.jar"?
You have to do this, as this jar will contain the stubs which
the client needs.After you have done the above and deployed it
put the jar file in the same directory where the client file
is present.This will help you in running the client successfully

And Ilya the J2ee server is not a bad one.I think everone who is
trying to learn EJB should start deploying first on the J2EE server before proceeding to other commericial servers because
this server is good in a academic point of you where you get to see what is happenning(The process run's in front of your eyes giving clues on what is happening on the background)unlike a
server like Weblogic6.0 where you run commands which will do the
job for you but you won't know what exactly happened on the background.
Hope this helps,
Manjunath
P.S Rohit :I think this will also help you in your other question which you had posted regarding the the two ejb's not working concurrently.Put the jar files for both the ejb's in the same directory where your client class file is present.
[This message has been edited by Manjunath Subramanian (edited August 18, 2001).]
[This message has been edited by Manjunath Subramanian (edited August 18, 2001).]
 
rohit aggarwal
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi manju,
thanks for helping me,
i want to know one thing from you about directory structure.
when i deploy the application in j2ee,
the web part is stored in root directory i.e j2sdkee1.2.1/public_html/applicationName/*.jsp
j2sdkee1.2.1/public_html/applicationName/web-inf/classes/*.class
here *.class are the javBeans that act as clients to ejbs
and ejb jars are stored in
j2sdkee1.2.1/repository/machineName/applications/*.jar
where jar has sellLoginClient.jar,sellLogin1823703Server.jar andsellLogine6014793825.jar
now if i donot check the return client, i think it automaticaaly creats that client.jar into it.
I have tried what you have told but of no use,
either i am doing it in wrong way.
i am getting one client.jar for one application.
please tell me in steps what i have to do.
i have LoginEJB.class and CategoryEJB.calss plus their homes and Remotes.
LoginBean.class and CategoryBean.class javaBeans acts as cleints for their respective EJBbeans.
two jsp files Login.jsp and category.jsp.
first file of application to be called is category.jsp which checks the sessions for user.
please tell me what i have to do from scratch with there directory structure.
with thanks,
rohit
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try giving the full package name
ie
as below
catHome = (ejbBeans.CategoryHome.class) PortableRemoteObject.narrow(objref,ejbBeans.CategoryHome.class);
//Your code is below.
catHome = (CategoryHome) PortableRemoteObject.narrow(objref,ejbBeans.CategoryHome.class);
 
Thank you my well lotioned goddess! Here, have my favorite tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic