• 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
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

very strange error

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi I am new to EJB and trying to execute my first application
but I am getting the following error please help me in finding out the solution
---------------
java.lang.ClassCastException
at com.sun.corba.ee.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:296)
at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:137)
at HelloClient.main(HelloClient.java:16)
---------------------------------------
Here I am pasting my Java Code
** Home Object **
import javax.ejb.*;
import java.rmi.RemoteException;
public interface HelloHome extends EJBHome
{
Hello create() throws RemoteException,CreateException;
}
==================================
** Remote Interface **
import javax.ejb.*;
import java.rmi.RemoteException;
import java.rmi.Remote;
public interface Hello extends EJBObject
{
public String hello() throws java.rmi.RemoteException;
}
========================
** My Bean **
import javax.ejb.*;
public class HelloBean implements SessionBean
{
public void ejbCreate()
{
System.out.println("ejbCreated()");
}
public void ejbRemove()
{
System.out.println("ejbRemove()");
}
public void ejbActivate()
{
System.out.println("ejbActivate()");
}
public void ejbPassivate()
{
System.out.println("ejbPassivate()");
}
public void setSessionContext(SessionContext ctx)
{
System.out.println("setSessionContext()");
}
// Business methods
public String hello()
{
System.out.println("Hello()");
return "Hello World!";
}
}
===========================
** Client ******
import javax.ejb.*;
import javax.naming.*;
import javax.rmi.*;
import java.util.Properties;
//import javax.rmi.PortableRemoteObect;
public class HelloClient
{
public static void main(String[] args)
{
try
{
Properties props=System.getProperties();
Context ctx=new InitialContext(props);
Object obj = ctx.lookup("HelloBean");
HelloHome home= (HelloHome) PortableRemoteObject.narrow(obj, HelloHome.class);
Hello hello=home.create();
System.out.println(hello.hello());
hello.remove();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
=====================================
Please Help I have been stuck here since 8 days not finding any solution.
Thanking you in advance
Saradhi

------------------
Intelligent Hard work never goes waste
 
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I recommend to follow the tutorial provided by Sun at J2EE It gives step by step procedure, how to build and deploy EJB's on J2EE RI.

Originally posted by saradhi74:

Hi I am new to EJB and trying to execute my first application
but I am getting the following error please help me in finding out the solution
---------------
java.lang.ClassCastException
at com.sun.corba.ee.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:296)
at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:137)
at HelloClient.main(HelloClient.java:16)



------------------
Sreenivasa Kumar Majji
Sun Certified Java Programmer
SCJP Mock Test
 
Ranch Hand
Posts: 1871
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
saradhi74

The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please log in with a new name which meets the requirements.
Thanks.
------------------

Mahindrakar
IBM Application Server Forum Moderator

Consultant - Zensar Technologies ,Pune India.
SCJP2, SCJD2 & SCJEA (Part I)
 
My favorite is a chocolate cupcake with white frosting and tiny ad sprinkles.
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic