This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

very strange error

 
Pardha
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • 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
 
Sreenivasa Majji
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • 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
 
Rahul Mahindrakar
Ranch Hand
Posts: 1868
  • Mark post as helpful
  • send pies
  • 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)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic