File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes error: java.lang.ClassCastException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "error: java.lang.ClassCastException" Watch "error: java.lang.ClassCastException" New topic

error: java.lang.ClassCastException

Ajoy Sharma

Joined: Feb 24, 2004
Posts: 18
Iam facing error : java.lang.ClassCastException. It giving error at this point in my client code : ServerHome serverhome =(ServerHome) javax.rmi.PortableRemoteObject.narrow(obj,ServerHome.class);
could any body tell me plz how can solve it.
code is givin below.
thanks for ur help.

import javax.ejb.*;
import java.awt.*;
import java.awt.event.*;
import javax.rmi.*;
import java.rmi.*;
import javax.swing.event.*;
import javax.swing.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import java.util.Hashtable;
import java.util.Properties;
import javax.ejb.CreateException;
public class Client {
public static void main(String[] args){
Properties env = new Properties();
env.put("java.naming.provider.url", "iiop://localhost:3700");
Context context = new InitialContext(env);
Object obj = context.lookup("ejb/ServerObject"); //Server ejb-name
System.out.println("Working here anand");
ServerHome serverhome =(ServerHome) javax.rmi.PortableRemoteObject.narrow(obj,ServerHome.class);
Server server = serverhome.create();
String Message = JOptionPane.showInputDialog("Enter Your Message");
JOptionPane.showMessageDialog(null, server.performAction(Message) );

catch(Exception e){
JOptionPane.showMessageDialog(null ,"Exception is " +e);
Georg Joo
Ranch Hand

Joined: Feb 24, 2004
Posts: 49
Be sure, that your Client JAR File is in the CLASSPATH.

SCJP, SCWCD, SCBCD<br /> <br />Vienna, Austria
I agree. Here's the link:
subject: error: java.lang.ClassCastException
It's not a secret anymore!