我是 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();
}
}
}
任何人都可以帮我解决这个问题吗?
提前致谢 Renjith M