如何避免 Java RMI 的 MarshalException?
我刚刚用 java rmi 完成了一个小程序,但不知何故它不起作用。每次我想启动服务器时,我都会收到 MarshalException。关于如何实现远程方法调用的接口,我应该注意哪些要点?我认为可以创建一个实现,但也可以在实现类中包含一些附加方法,例如构造函数或私有变量。
这不应该有效吗?
问候
I just finished a small program with java rmi and somehow it doesn't work. Everytime I want to start the server I'm getting the MarshalException. Are there any important points that I should be aware of them on how to implement the interface for the remote method invocation? I thought it would be possible to create an implementation but also include some additional methods like a constructor or private variables inside of the implementing class.
Shouldn't this just work?
Greetings
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了能够传输对象,您需要使它们实现
Serialized
。也许有一个默认的(无参数)构造函数(但这不是序列化的要求)正如helios指出的,不仅是类,而且所有字段层次结构(字段的类及其字段的类)都必须是<代码>可序列化)
In order to be able to transfer objects you need to make them implement
Serializable
. And perhaps have a default (no-arg) constructor (this is not a requirement for serialization though)As helios noted, not only the class, but all your field hierarchy (classes of fields, and the classes of their fields) must be
Serializable
)这就是你的问题。客户端需要该类。
There's your problem. That class is required at the client.