File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes java.lang.ClassCastException at com. 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 "java.lang.ClassCastException at com." Watch "java.lang.ClassCastException at com." New topic
Author

java.lang.ClassCastException at com.

Ajoy Sharma
Greenhorn

Joined: Feb 24, 2004
Posts: 18
Hi,
Iam facing this problem .Any body can help me to solve this problem.
Caught an unexpected exception!
java.lang.ClassCastException
at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:293)
at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:134)
at ConverterClient.main(ConverterClient.java:50)
Client Code is given below:
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import java.util.Properties;
import javax.ejb.CreateException;
// NOT NECESSARY import Converter;
// NOT NECESSARY import ConverterHome;
public class ConverterClient {
public static void main(String[] args) {
try {
Properties env = new Properties();
env.put("java.naming.factory.initial","com.sun.jndi.cosnaming.CNCtxFactory");
env.put("java.naming.provider.url", "iiop://localhost:3700");
Context initial = new InitialContext(env);
ConverterHome home =(ConverterHome)PortableRemoteObject.narrow(initial.lookup("MyConverter"),ConverterHome.class);

// Create converter session bean
Converter currencyConverter = home.create();
// Calculate from dollars to yen
double amount = currencyConverter.dollarToYen(100.00);
System.out.println("100 Dollars is " + String.valueOf(amount) + " Yen");
// Calculate from yen to dollars
amount = currencyConverter.yenToEuro(100.00);
System.out.println("100 Yen is " + String.valueOf(amount) + " Dollars");
} catch (Exception ex) {
System.err.println("Caught an unexpected exception!");
ex.printStackTrace();
}
}
}
Nandini Sriram
Ranch Hand

Joined: Jul 04, 2003
Posts: 132
Hi,
Not sure what the cause could be. Please take a look at Sun's FAQ-maybe you can find a solution here.
Regards,
Nandini


Discipline, Dedication and Determination define Destiny.
Ajoy Sharma
Greenhorn

Joined: Feb 24, 2004
Posts: 18
HI Nandini,
Iam still facing this problem. Iam struggling from last 4 days to resolve this problem.plz help me to resolve this problem.
If u find any solution Plz mail me: anand_m_sharma@yahoo.com
Error :
Caught an unexpected exception!
java.lang.ClassCastException at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:293)
at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:134)
at ConverterClient.main(ConverterClient.java:59)
Dana Hanna
Ranch Hand

Joined: Feb 28, 2003
Posts: 227
I'd have to assume that the result of initial.lookup("MyConverter") is not of type ConverterHome.
Maybe you could print out a debug line after the lookup:
Object obj = initial.lookup("MyConverter");
//what type do we have - is it what we thought?
System.out.println(obj.getClass());
//now narrow it
ConverterHome home =(ConverterHome)PortableRemoteObject.narrow(obj,ConverterHome.class);
Ajoy Sharma
Greenhorn

Joined: Feb 24, 2004
Posts: 18
Thanks For reply.
I try ur logic but iam still unable to resolve this problem.
Could u tell me what i will do next to resolve this problem.
I am struggling from last 4 days. could u help me plz.
when i use ur code
System.out.println(objref.getClass());
this gives out put :::
class com.sun.corba.se.internal.iiop.CDRInputStream_1_0$1

Caught an unexpected exception!
java.lang.ClassCastException
at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:293)
at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:134)
at ConverterClient.main(ConverterClient.java:69)
thnsk waiting for ur response.
Anand
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.lang.ClassCastException at com.
 
Similar Threads
how to connect EJB without using runclient
PoratableRemoteObject
How to run a client...
Getting Class cast exception while Lookup EJB2.1 session bean using JNDI name in WAS6.1
class not found error!!