例外“远程对象实现非法远程接口”?

时间:2012-09-29 17:40:53

标签: java rmi

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

这是我的代码,愿有人帮助我吗?

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();
           }
}

1 个答案:

答案 0 :(得分:34)

Remote接口中的每个方法都必须能够抛出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