执行
IpAddress ip = (IpAddress)Naming.lookup("127.0.0.1/IpAddress");
是报错:
Exception in thread "main" java.lang.ClassCastException: com.mask85.rmi.IpAddress_Stub之前已经升成了IpAddress_Stub,配置了policy。不明白~~~~为什么

解决方案 »

  1.   

    原码如下:
    接口public interface IpAddressI extends Remote {
           public String getIp() throws RemoteException;
           public void setIp(String ip) throws RemoteException;
    }
    类:
    public class IpAddress extends UnicastRemoteObject implements IpAddressI {
    private String ip; public IpAddress() throws RemoteException {
    }
    public String getIp() throws RemoteException {
    // TODO 自动生成方法存根
    return ip;
    } public void setIp(String ip) throws RemoteException {
    // TODO 自动生成方法存根
    this.ip = ip;
    }
    }////public class IPDNS { public static void main(String[] args) throws Exception {
    System.setSecurityManager( new RMISecurityManager()); IpAddress ip = new IpAddress(); Naming.bind( "IpAddress", ip); System.out.println("Ready to do time");
    }
    }
    ///
    客户端:
    public class Test { public static void main(String[] args)throws Exception {
    System.setSecurityManager(new RMISecurityManager());
    System.out.println("x");
    Naming.lookup("//211.92.10.71/IpAddress");

    }
    }
      

  2.   

    改成: IpAddressI ip = (IpAddressI)Naming.lookup("127.0.0.1/IpAddress");
    IpAddress是部署在服务器端的实现类
      

  3.   

    这样做了,还是同样的错,现在的客户端可以找到服务器实现的类,问题是不是cast。
      

  4.   

    如果是单一的转型错误
    IpAddressI ip = (IpAddressI)Naming.lookup("127.0.0.1/IpAddress");
    这么改应该是对的!
      

  5.   

    就是呀,报错java.lang.ClassCastException: com.mask85.rmi.IpAddress_Stub