1
這裏是我的代碼:
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);
}
如果將方法更改爲public void joinNetwork(PeerInterface p)會拋出RemoteException,該怎麼辦? – StanislavL
我得到了同樣的錯誤 – Enrico