执行
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。不明白~~~~为什么
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。不明白~~~~为什么
接口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");
}
}
IpAddress是部署在服务器端的实现类
IpAddressI ip = (IpAddressI)Naming.lookup("127.0.0.1/IpAddress");
这么改应该是对的!