• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java.lang.ClassCastException at com.

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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();
}
}
}
 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ajoy Sharma
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Clowns were never meant to be THAT big! We must destroy it with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic