日期:2014-05-20  浏览次数:20778 次

jboss部署的问题
客户端老是报这个错 
Exception in thread "main" java.lang.ClassCastException 
at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(Unknown Source) 
at javax.rmi.PortableRemoteObject.narrow(Unknown Source) 
at testsession.CountClient.main(CountClient.java:20) 
Caused by: java.lang.ClassCastException: $Proxy1 
... 3 more 

public class CountClient { 
public static void main(String[] a) throws Exception{ 
java.util.Properties p = new java.util.Properties(); 
  p.put(Context.INITIAL_CONTEXT_FACTORY, 
  "org.jnp.interfaces.NamingContextFactory"); 
  p.put(Context.URL_PKG_PREFIXES, "jboss.naming:org.jnp.interfaces"); 
  p.put(Context.PROVIDER_URL, "jnp://localhost:1099"); 
   
  Context ctx = new InitialContext(p); 
  Object ref = ctx.lookup("JNDICountBean"); 
   
  System.out.println("#############"+ref.getClass().getName()); 
   
  CountHome countHome = (CountHome) PortableRemoteObject.narrow( 
  ref, CountHome.class); 
  Count count = countHome.create(); 
  //System.err.println(ref.getClass().getName()); 
  //HelloLocalHome helloHome = (HelloLocalHome) ref;  
  //HelloLocal hello = helloHome.create(); 
   
  System.out.println(count.count()); 






------解决方案--------------------
CountHome countHome = (CountHome) PortableRemoteObject.narrow(ref, CountHome.class); 

类转换错误, 看看PortableRemoteObject.narrow(ref, CountHome.class)的class是什么。