【问题标题】:Getting java.rmi.UnmarshalException: unrecognized method hash: method not supported by remote object获取 java.rmi.UnmarshalException:无法识别的方法哈希:远程对象不支持的方法
【发布时间】:2009-12-22 14:52:03
【问题描述】:

我是 RMI 技术的新手。

当我运行 rmi 客户端程序时,我收到异常:java.rmi.UnmarshalException: unrecognized method hash: method not supported by remote object。 我正在使用 jdk1.5

远程方法的参数是序列化对象。

这些是服务器代码...

这是远程接口

package interfacepackage;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface ServerInterface extends Remote{

     public void getOrder(Order order) throws RemoteException;
}

这是服务端实现类

public class ServerImplementation implements ServerInterface {
    public ServerImplementation() throws RemoteException {
    }

    public void getOrderFromCash(Order order) throws RemoteException {
        System.out.println("WORKED");
    }
public static void main(String[] args) 

        try {
            java.rmi.registry.LocateRegistry.createRegistry(1234);
            ServerImplementation service = new ServerImplementation();
            ServerInterface myRemoteObject = (ServerInterface) UnicastRemoteObject
                    .exportObject(service, 0);
            java.rmi.registry.Registry registry = java.rmi.registry.LocateRegistry
                    .getRegistry("localhost", 1234);
            registry.rebind("ServerImplementation", myRemoteObject);


        } catch (Exception ex) {
            ex.printStackTrace();

        }
    }
}

这是订单类

public class Order implements Serializable{
private static final long serialVersionUID = 1L;
private int id;
private String name;
public Order(int id,String name){
    this.id=id;
    this.name=name;
}
}

我在客户端也有相同的接口和订单类。

这是客户端代码

public class TestClientProgram {

    public static void main(String[] args)  {
        try{
         java.rmi.registry.Registry registry = java.rmi.registry.LocateRegistry.getRegistry("localhost",1234);
         ServerInterface service=(ServerInterface) registry.lookup("ServerImplementation");
         Order orderObject=new Order(1,"dish");
         service.getOrderFromCash(orderObject);
        }
        catch(Exception e){
            e.printStackTrace();    
        }
        }
    }

谁能帮我解决这个问题?

提前致谢 伦吉斯 M

【问题讨论】:

  • 你开始 rmiregistry 了吗?

标签: java exception rmi unmarshalling


【解决方案1】:

异常表示服务端找不到方法,由客户端调用(错误信息有点误导)。一个可能的原因可能是服务器和客户端使用不同的类路径运行,并且代码已被修改得足以使 RMI 接口不兼容。

【讨论】:

  • 该消息有什么误导性?它说“远程对象不支持的方法”,这正是您在此处描述的内容。
【解决方案2】:

这里出了点问题。您的ServerInterface 有一个getOrder 方法,但实现有getOrderFromCash。我会检查以确保所有代码都使用相同版本的接口编译和执行。

【讨论】:

    【解决方案3】:

    嗯,这是一个迟到的答案,但它可能会对新用户有所帮助。

    我正在使用 RMI(客户端和服务器) 我得到了同样的错误,一切都是正确的,但我错过的是在服务器接口中定义函数,而它是在客户端接口中定义的!!

    我希望这个答案对你有帮助:)

    【讨论】:

    • RMI中没有Server接口和Client接口之类的东西。有一个远程接口。在服务器和客户端,它必须是相同的,我的意思是按位相同。
    【解决方案4】:

    在 ServerInterface 中,您应该将 getOrder 替换为 getOrderFromCash。

    【讨论】:

      猜你喜欢
      • 2016-10-17
      • 1970-01-01
      • 2014-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-05
      相关资源
      最近更新 更多