2012-06-20 86 views
0

我正在制作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中的串行....但它不是我的情况发生

+0

您是如何执行客户端和服务器的? ImageIcon实现了Serializable,所以它可以通过网络发送,但在你的情况下,反序列化似乎存在问题。从ImageIcon的文档:“警告:此类的序列化对象将与未来的Swing版本不兼容。当前的序列化支持适用于运行相同版本的Swing的应用程序之间的短期存储或RMI。”你的客户端和服务器使用相同版本的Swing吗? – joergl

+0

好吧....是的...我在本地运行它........ –

+0

简单的实验:尝试用别的东西代替'ImageIcon',比如'String'。你仍然得到相同的异常? – biziclop

回答

2

同样的问题发生。当我试图通过的ImageIcon通过RMI对象....

长的检查之后....我发现我specifed的网址不正确.....

它发生......在此编者常常表现为解组异常准确如你所示.......

尝试检查您的本地URL .....

+0

你说得对。....我有一个小的网址规范....但仍不明白为什么这显示Unmarshal异常,因为它与序列化没有任何关系....我相信... –

+0

好..即使我不知道有关该....的很多细节....只是明白了.. .. lolz .. – 2012-06-20 16:36:49