获取java.rmi.UnmarshalException:无法识别的方法哈希:远程对象不支持的方法 [英] Getting java.rmi.UnmarshalException: unrecognized method hash: method not supported by remote object
问题描述
我是RMI技术的新手。
I am new to RMI technology.
当我运行rmi客户端程序时,我得到异常:java.rmi.UnmarshalException:无法识别的方法哈希:远程对象不支持的方法。
我使用的是jdk1.5
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
远程方法的参数是Serialized对象。
The argument of the remote method is the Serialized object.
这些是服务器代码......
These are the server code...
这是远程接口
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;
}
}
我在Client中也有相同的Interface和Order类。
I have the same Interface and Order class in Client also.
这是客户代码
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 ?
在此先感谢
Renjith M
Thanks In Advance Renjith M
推荐答案
该异常表示服务器无法找到客户端调用的方法(错误消息略有误导)。一个可能的原因可能是服务器和客户端使用不同的类路径运行,并且代码已经被修改到足以使RMI接口不兼容。
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.
这篇关于获取java.rmi.UnmarshalException:无法识别的方法哈希:远程对象不支持的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!