获取 java.rmi.UnmarshalException:无法识别的方法哈希:远程对象不支持方法

发布于 2024-08-15 16:14:38 字数 2144 浏览 5 评论 0原文

我是 RMI 技术的新手。

当我运行 rmi 客户端程序时,出现异常: java.rmi.UnmarshalException: 无法识别的方法哈希:远程对象不支持方法。 我使用的是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();    
        }
        }
    }

有人可以帮我解决这个问题吗?

提前致谢 伦吉斯 M

I am new to RMI technology.

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

梅倚清风 2024-08-22 16:14:38

该异常表明服务器无法找到客户端调用的方法(错误消息略有误导性)。一种可能的原因可能是服务器和客户端使用不同的类路径运行,并且代码已被修改得足以导致 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.

终难愈 2024-08-22 16:14:38

这里出了点问题。您的 ServerInterface 有一个 getOrder 方法,但实现有 getOrderFromCash。我会检查以确保所有代码都使用该接口的相同版本进行编译和执行。

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.

寄意 2024-08-22 16:14:38

在 ServerInterface 中,您应该将 getOrder 替换为 getOrderFromCash。

In ServerInterface you should replace getOrder with getOrderFromCash.

メ斷腸人バ 2024-08-22 16:14:38

好吧,这是一个迟到的答案,但它可能会对新用户有所帮助。

我正在使用 RMI(客户端和服务器)
我得到了同样的错误,一切都是正确的,但我错过的是在服务器接口中定义该函数,而它是在客户端接口中定义的!

我希望这个答案能帮助你:)

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 !!

I hope this answer will help u :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文