[英]Getting java.rmi.UnmarshalException: unrecognized method hash: method not supported by remote object
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. 当我运行rmi客户端程序时,我得到异常:java.rmi.UnmarshalException:无法识别的方法hash:远程对象不支持的方法。 I am using jdk1.5 我使用的是jdk1.5
The argument of the remote method is the Serialized object. 远程方法的参数是Serialized对象。
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. 我在Client中也有相同的Interface和Order类。
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.
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接口不兼容。
Something's wrong here. 这里有点不对劲。 Your ServerInterface
has a getOrder
method but the implementation has getOrderFromCash
. 您的ServerInterface
有一个getOrder
方法,但实现有getOrderFromCash
。 I would check to make sure all the code is compiled and executed with the same versions of that interface. 我会检查以确保所有代码都使用该接口的相同版本进行编译和执行。
在ServerInterface中,您应该使用getOrderFromCash替换getOrder。
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 :) 我希望这个答案能帮助你:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.