java中的非法远程方法

Ran*_*nge 45 java runtime-error rmi illegalargumentexception

这是我第一次使用java Rmi*.我有一个自定义类,它扩展UnicastRemoteObject并实现了一个扩展远程的接口.我认为我已经在类中正确实现了接口的方法,但是IllegalArgumentException当我尝试运行我的代码时,我仍然得到了一个(而且它是关于一个没有参数的方法).

jvm声称遇到了非法的远程方法,但该方法及其实现对我来说似乎没问题.

是否有任何其他原因导致除了错误地实现或调用方法之外可能发生此异常?


这是堆栈跟踪:

SEVERE: null
java.rmi.server.ExportException: remote object implements illegal remote interface; nested exception is:
        java.lang.IllegalArgumentException: illegal remote method encountered: public abstract java.lang.String Node.getId()
        at sun.rmi.server.UnicastServerRef.exportObject(Unknown Source)
        at java.rmi.server.UnicastRemoteObject.exportObject(Unknown Source)
        at java.rmi.server.UnicastRemoteObject.exportObject(Unknown Source)
        at java.rmi.server.UnicastRemoteObject.<init>(Unknown Source)
        at java.rmi.server.UnicastRemoteObject.<init>(Unknown Source)
        at NodeImpl.<init>(NodeImpl.java:30)
        at NodeLauncher.main(NodeLauncher.java:11)
Caused by: java.lang.IllegalArgumentException: illegal remote method encountered: public abstract java.lang.String Node.getId()
        at sun.rmi.server.Util.checkMethod(Unknown Source)
        at sun.rmi.server.Util.getRemoteInterfaces(Unknown Source)
        at sun.rmi.server.Util.getRemoteInterfaces(Unknown Source)
        at sun.rmi.server.Util.createProxy(Unknown Source)
        ... 7 more
Run Code Online (Sandbox Code Playgroud)

这是界面:

import java.rmi.*;
import java.util.LinkedList;

interface Node extends Remote
{
    public boolean isAlive();

    public LinkedList<NodeImpl> getLeafNodes();

    public LinkedList<NodeImpl> getNeighborhoodList();

    public String [] getRoutingTable();

    public NodeImpl initiation(String credentials,Object application);

        public String route(String message,String key);

        public void inform(byte [] id);

        public String getId();

        public boolean isConnected();

        public void applicationClose();

        public boolean distanceMeasure();
}
Run Code Online (Sandbox Code Playgroud)

这是类的构造函数:

public NodeImpl() throws RemoteException
    {
        super();
        l=4;
        M=1;
        nodeId=new byte [16];
        Random r=new Random();
        r.nextBytes(nodeId);
        leafNodes=new LinkedList<NodeImpl>();
        connected=false;
        ng=new NodeGUI(this);

        for(int i=0;i<l;i++)
        {
            leafNodes.add(null);
        }

        neighborhoodList=new LinkedList<NodeImpl>();
        anyNodeWhoAnswered=new LinkedList<byte []>();
        it=new InformingTimer(this);
        Thread informingTimerThread=new Thread(it);
        informingTimerThread.start();

        try 
        {
            Naming.rebind("rmi://" + "localhost" + ":1099/"+nodeId, this);
        }
        catch (Exception ex) 
        {
            Logger.getLogger(NodeImpl.class.getName()).log(Level.SEVERE, null, ex);
        }

        bootstrap();
    }
Run Code Online (Sandbox Code Playgroud)

ska*_*man 83

RMI Remote接口上的所有方法都必须RemoteException在其throws子句中声明,例如:

public String getId() throws RemoteException;
Run Code Online (Sandbox Code Playgroud)

目前尚不清楚为什么异常名称getId()具体,它可能只是它检查的第一种方法.

此外,getLeafNodes()getNeighborhoodList()方法应该有一个指定返回类型Node,不是NodeImpl,否则他们很可能会失败也.