java 异常“远程对象实现非法远程接口”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12654942/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 09:43:12  来源:igfitidea点击:

Exception "remote object implements illegal remote interface"?

javarmi

提问by Jeffrey

I use rmi in Java. however there is a ExportException "remote object implements illegal remote interface".

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

Here is my code, May someone help me?

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

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

回答by Jeffrey

Every method in a Remoteinterface must be able to throw a RemoteException. Your interface should be:

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

You might want to take a look at the RMI Tutorial.

您可能想看看RMI 教程