gpt4 book ai didi

java - 异常 "remote object implements illegal remote interface"?

转载 作者:搜寻专家 更新时间:2023-10-30 19:50:16 27 4
gpt4 key购买 nike

我在 Java 中使用 rmi。但是有一个 ExportException“远程对象实现非法远程接口(interface)”。

这是我的代码,有人可以帮帮我吗?

public interface RemotePeer extends Remote {

public abstract void displayInf(String inf);

public abstract void exit();

public abstract boolean isActive();
}


public class Peer implements RemotePeer{
public Peer(){}
....

public static void main(String[] args) {
Peer p=new Peer()
RemotePeer remoteP=(RemotePeer) UnicastRemoteObject.exportObject(p, 0);
Registry registry = LocateRegistry.getRegistry();
}
}

最佳答案

Remote 接口(interface)中的每个方法都必须能够抛出 RemoteException。你的界面应该是:

public interface RemotePeer extends Remote {

public abstract void displayInf(String inf) throws RemoteException;

public abstract void exit() throws RemoteException;

public abstract boolean isActive() throws RemoteException;
}

您可能想看一下 RMI Tutorial .

关于java - 异常 "remote object implements illegal remote interface"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12654942/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com