这是我的代码:
public class PeerNode extends UnicastRemoteObject implements PeerInterface {
private PeerInterface joint;
private List<PeerNode> neighbours;
public PeerNode(String s, int idnumber) throws IOException {
PeerNode.setNome(s);
PeerNode.setKey(idnumber);
this.neighbours = new ArrayList<>();
System.out.println("Peer node initialized");
System.out.println(this);
}
public void contactExistingNode(String node) throws Exception, RemoteException, NotBoundException {
System.out.println("I know the peer "+ node);
System.out.println("I try to join automatically the network");
joint = (PeerInterface) registry.lookup(node);
joint.joinNetwork(this);
}
这是界面:
public interface PeerInterface extends Remote {
public void joinNetwork(PeerNode p) throws RemoteException;
}
我试图传递对象远程对等...并在此行
joint.joinNetwork(this);
我有这个错误:
Exception in thread "main" java.lang.IllegalArgumentException: argument type mismatch
...
at com.sun.proxy.$Proxy0.joinNetwork(Unknown Source)
at com.server.PeerNode.contactExistingNode(PeerNode.java:41)
at com.server.Main.main(Main.java:51)
我已经把它作为PeerInterface,PeerNode ......但它不起作用。 有人可以帮帮我吗? 这是接收对象的类
public void joinNetwork(PeerNode p) throws RemoteException {
neighbours.add(p);
}
答案 0 :(得分:2)
客户端没有远程对象的实例。它有一个远程接口的实例。远程方法的签名应该是
void joinNetwork(PeerInterface peer) throws RemoteException;
修复远程接口,远程对象和客户端;重新编译;重新部署;并重新测试。