【问题标题】:Exception "remote object implements illegal remote interface"?异常“远程对象实现非法远程接口”?
【发布时间】:2012-09-21 05:16:52
【问题描述】:

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

【问题讨论】:

  • 你试过使用 UnicastRemoteObject 吗?
  • @Abu 为什么?那会有什么不同?

标签: java rmi


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-28
    • 1970-01-01
    • 1970-01-01
    • 2012-01-03
    • 2010-09-07
    • 1970-01-01
    • 2019-03-04
    相关资源
    最近更新 更多