java - 获取 java.rmi.UnmarshalException : unrecognized method hash: method not supported by remote object

标签 java exception rmi unmarshalling

我是 RMI 技术的新手。

当我运行 rmi 客户端程序时,出现异常:java.rmi.UnmarshalException: unrecognized method hash: method not supported by remote object。 我用的是jdk1.5

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

这些是服务器代码...

这是远程接口(interface)

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();

        }
    }
}

这是类(class)订单

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 类。

这是客户端代码

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();    
        }
        }
    }

谁能帮我解决这个问题?

提前致谢 伦 git M

最佳答案

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

关于java - 获取 java.rmi.UnmarshalException : unrecognized method hash: method not supported by remote object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1946841/

相关文章:

java - JAXB DOM 节点解码省略元素

c# - ScreenShot上的GDI +一般错误

java - "BindException: Address already in use"在同一台电脑上使用java套接字传输文件时出现异常

java - 命令行选项适用于 Windows,但不适用于 Linux

java - RMI重连问题

java - 我想要可以在 Windows、Mac 和 Linux 中打开“打开方式”对话框的 java 程序?

java - 我从服务方法中收到 NullPointerException

java - 每 2 小时执行一次 Java 定时器

java - 找不到文件java

java - 处理java RMI连接拒绝主机异常