• 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

Exception in thread Exception in thread "main" java.lang.ClassCastException

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am running JBoss 4.2 and JDK 1.5. I try to run the following client class below I receive the error . Exception in thread Exception in thread "main" java.lang.ClassCastException
at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:229)
at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:137)
at simplebean.client.SimpleBeanClient.createBean(SimpleBeanClient.java:44)
at simplebean.client.SimpleBeanClient.main(SimpleBeanClient.java:37)
Caused by: java.lang.ClassCastException: $Proxy0
at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:212)

JAVA CLASS
/**
*
*/
package simplebean.client;

import java.rmi.RemoteException;
import java.util.Properties;

import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;

import simplebean.interfaces.Simple;
import simplebean.interfaces.SimpleHome;

/**
* @author owner
*
*/
public class SimpleBeanClient {
Properties properties;

public SimpleBeanClient() {
properties = new Properties();
properties.put("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
properties.put("java.naming.factory.url.pkgs",
"org.jboss.naming rg.jnp.interfaces");
properties.put("java.naming.provider.url", "jnp://localhost:1099");
properties.put("jnp.disableDiscovery", "true");
}

public static void main(String[] args) {
SimpleBeanClient beanClient = new SimpleBeanClient();
beanClient.createBean();
}

public void createBean() throws EJBException {
try {
InitialContext context = new InitialContext(properties);
Object object = context.lookup("ejb/SimpleBeanHome");
SimpleHome simpleHome = (SimpleHome) PortableRemoteObject.narrow(
object, SimpleHome.class);
Simple simple = simpleHome.create();
simple.setName("Gunter");
System.out.println(simple.getId());
System.out.println(simple.getName());
} catch (NamingException e) {
throw new EJBException(e);
} catch (RemoteException e) {
throw new EJBException(e);
} catch (CreateException e) {
throw new EJBException(e);
}
}
}
 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Assuming that your test client is compiling fine, the cause could be :

1) The object on the naming service located under the "ejb/SimpleBeanHome" is not a simplebean.interfaces.SimpleHome
2) The object on the naming service located under the "ejb/SimpleBeanHome" is not implementing javax.ejb.EJBHome
3) The object on the naming service located under the "ejb/SimpleBeanHome" is implementing only javax.ejb.EJBLocalHome
4) The simplebean.interfaces.SimpleHome located on the client is not the same deployed on the AS.

Regards,
Andrea
 
I wish to win the lottery. I wish for a lovely piece of pie. And I wish for a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic