• 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
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

ClassCastException in client

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
You will always be treated with dignity. Now, strip naked, get on the probulator and hold this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic