Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes ClassCastException in client Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "ClassCastException in client " Watch "ClassCastException in client " New topic
Author

ClassCastException in client

Rajesh Srivastava
Greenhorn

Joined: May 14, 2004
Posts: 25
Hi,
This problem occured to me while running the client code (HeadFirst EJB page 57)
after successful deployment of Advice EJB.

C:\EJB\projects\advice>java -cp .;c:\EJB\projects\AdviceAppClient.jar;D:\j2sdkee
1.3.1\lib\j2ee.jar;C:\EJB\projects\advice\classes AdviceClient
java.lang.ClassCastException
at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(Porta
bleRemoteObject.java:293)
at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:134)
at AdviceClient.go(AdviceClient.java:15)
at AdviceClient.main(AdviceClient.java:9)

I used following code for client (given on HFE page 57) :

import javax.naming.*;
import java.rmi.*;
import javax.rmi.*;
import headfirst.*;
import javax.ejb.*;

public class AdviceClient {
public static void main(String [] args) {
new AdviceClient().go();
}
public void go() {
try {
Context ic = new InitialContext();
Object o = ic.lookup("Advisor");
AdviceHome home = (AdviceHome)PortableRemoteObject.narrow(o, AdviceHome.class);
Advice advisor = home.create();
System.out.println(advisor.getAdvice());
} catch(Exception ex) {
ex.printStackTrace();
}
}
}

I am using following versions of JSDK and J2SDKEE: j2sdk1.4.0 and j2sdkee1.3.1

Looking forward to help,
rajesh - SCJP (1.4)
Joyce Lee
Ranch Hand

Joined: Jul 11, 2003
Posts: 1392
Rajesh, for window, use the following commands to compile and run:

To compile:
c:\HF>javac -classpath %CLASSPATH%;AdviceAppClient.jar AdviceClient.java

To run:
c:\HF>java -cp %CLASSPATH%;AdviceAppClient.jar AdviceClient

You don't to have the substitute CLASSPATH with ".;c:\EJB\projects\AdviceAppClient.jar;D:\j2sdkee
1.3.1\lib\j2ee.jar;".

For window, the command is slightly different from UNIX. It uses %.

HTH,
Joyce
[ May 16, 2004: Message edited by: Joyce Lee ]
Surendra Poranki
Greenhorn

Joined: May 16, 2004
Posts: 5
Try These

To Compile
C:\projects\advice>javac -classpath "%CLASSPATH%;AdviceAppClient.jar" AdviceClient.java


To Run
C:\projects\advice>java -cp "%CLASSPATH%;AdviceAppClient.jar" AdviceClient

When u run if u get the Corba.Error try to change the name of the getAdvice() method to something else and redeploy it .


Originally posted by Rajesh Srivastava:
Hi,
This problem occured to me while running the client code (HeadFirst EJB page 57)
after successful deployment of Advice EJB.

C:\EJB\projects\advice>java -cp .;c:\EJB\projects\AdviceAppClient.jar;D:\j2sdkee
1.3.1\lib\j2ee.jar;C:\EJB\projects\advice\classes AdviceClient
java.lang.ClassCastException
at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(Porta
bleRemoteObject.java:293)
at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:134)
at AdviceClient.go(AdviceClient.java:15)
at AdviceClient.main(AdviceClient.java:9)

I used following code for client (given on HFE page 57) :

import javax.naming.*;
import java.rmi.*;
import javax.rmi.*;
import headfirst.*;
import javax.ejb.*;

public class AdviceClient {
public static void main(String [] args) {
new AdviceClient().go();
}
public void go() {
try {
Context ic = new InitialContext();
Object o = ic.lookup("Advisor");
AdviceHome home = (AdviceHome)PortableRemoteObject.narrow(o, AdviceHome.class);
Advice advisor = home.create();
System.out.println(advisor.getAdvice());
} catch(Exception ex) {
ex.printStackTrace();
}
}
}

I am using following versions of JSDK and J2SDKEE: j2sdk1.4.0 and j2sdkee1.3.1

Looking forward to help,
rajesh - SCJP (1.4)
Rajesh Srivastava
Greenhorn

Joined: May 14, 2004
Posts: 25
Thanx,
It worked after using classpath as shown. A corba error was displayed but it was removed on changing the name of function getAdvice() to getAdv(). But I could not get why name change removes the corba error ?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ClassCastException in client
 
Similar Threads
problem with creating client in J2ee
Client does not run - NoInitialContextException !
how to run a client?
how to run the AdviceClient
Problem while Running First Example Of HFEJB.