获取 java.rmi.UnmarshalException:无法识别的方法哈希:远程对象不支持的方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1946841/
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
Getting java.rmi.UnmarshalException: unrecognized method hash: method not supported by remote object
提问by user236919
I am new to RMI technology.
我是 RMI 技术的新手。
When I am running the rmi client program, I am getting the exception : java.rmi.UnmarshalException: unrecognized method hash: method not supported by remote object. I am using jdk1.5
当我运行 rmi 客户端程序时,出现异常:java.rmi.UnmarshalException:无法识别的方法哈希:远程对象不支持的方法。我正在使用 jdk1.5
The argument of the remote method is the Serialized object.
远程方法的参数是序列化对象。
These are the server code...
这些是服务器代码...
This is the Remote Interface
这是远程接口
package interfacepackage;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface ServerInterface extends Remote{
public void getOrder(Order order) throws RemoteException;
}
This is the server implementation class
这是服务器实现类
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();
}
}
}
This is the class Order
这是班级订单
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;
}
}
I have the same Interface and Order class in Client also.
我在客户端也有相同的接口和订单类。
This is the client code
这是客户端代码
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();
}
}
}
Could any one help me to how can I fix the problem ?
任何人都可以帮助我解决问题吗?
Thanks In Advance Renjith M
提前致谢 Renjith M
回答by jarnbjo
The exception indicates that the server is not able to find the method, which is invoked by the client (the error message is slightly misleading). One possible reason may be that the server and client are running with different classpaths and that the code has been modified enough for the RMI interfaces to be incompatible.
异常表示服务端找不到客户端调用的方法(错误信息有点误导)。一种可能的原因可能是服务器和客户端使用不同的类路径运行,并且代码已被修改到足以使 RMI 接口不兼容。
回答by Dan
Something's wrong here. Your ServerInterface
has a getOrder
method but the implementation has getOrderFromCash
. I would check to make sure all the code is compiled and executed with the same versions of that interface.
这里出了点问题。你ServerInterface
有一个getOrder
方法,但实现有getOrderFromCash
。我会检查以确保所有代码都是使用该接口的相同版本编译和执行的。
回答by Chris Sim
Well it's a late answer but it may help the new users.
嗯,这是一个迟到的答案,但它可能会帮助新用户。
I am using RMI (Client and Server) I got the same error and everything was correct, but what I missed is to define the function in the server's interface, while it was defined in the Client interface !!
我正在使用 RMI(客户端和服务器)我遇到了同样的错误,一切都是正确的,但我错过的是在服务器接口中定义函数,而它是在客户端接口中定义的!!
I hope this answer will help u :)
我希望这个答案能帮助你 :)
回答by Pranjal Patidar
In ServerInterface you should replace getOrder with getOrderFromCash.
在 ServerInterface 中,您应该用 getOrderFromCash 替换 getOrder。