我正在制作rmi client server based program
这是假设为pass Image object through remote object interfaces
。 客户端从服务器接收图像。java rmi传递ImageIcon对象
以下是我的代码....
在客户端的接口方法实现
public class ImageReceiver
{
public static ImageIcon imageicon;
public static void main(String Data[])
{
imageicon = new ImageIcon(url);
imageicon=remoteObject.getImageFromServer();
}
}
// The Details regarding the binding of remote objects are excluded since they are worling fine...
sendImage ...
public ImageIcon getImageFromServer() throws RemoteException;
在服务器
public ImageIcon getImageFromServer()
{
ImageIcon ic = new ImageIcon("local url specified");
return ic;
}
// Much of the Exceptions and other binding details are excluded for simpicity.....
现在的问题是,即时得到一个错误称为
java.rmi.UnmarshalException: error unmarshalling return
nested exception is: java.io.EOFException
现在,其实我没有太多的任何想法的它是怎么来...... 两大疑惑我是... 。
是否有可能通过rmi发送ImageIcon对象...?如果是的话,这里可能是错误的。如果没有,是否存在任何通过rmi传递基于图像的对象作为参数的简单方法...?
我还听说某处,javax.swing.ImageIcon中的串行....但它不是我的情况发生
您是如何执行客户端和服务器的? ImageIcon实现了Serializable,所以它可以通过网络发送,但在你的情况下,反序列化似乎存在问题。从ImageIcon的文档:“警告:此类的序列化对象将与未来的Swing版本不兼容。当前的序列化支持适用于运行相同版本的Swing的应用程序之间的短期存储或RMI。”你的客户端和服务器使用相同版本的Swing吗? – joergl
好吧....是的...我在本地运行它........ –
简单的实验:尝试用别的东西代替'ImageIcon',比如'String'。你仍然得到相同的异常? – biziclop