• Post Reply Bookmark Topic Watch Topic
  • New Topic

Unserializable error

 
Lin Shen
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a problem with object serialization.

I have a remote object A which contains a vector. It implements remote interface C, which contains a single method that returns this vector to the client side. Class A also has a setVector method that allows a server side class B to update the vector content. So the client always gets a fresh copy of the vector modified by class B when it invokes the remote call.

Everthing goes well before class B calls the setVector method. However, after class B calls setVector method to update the vector, an exception is thrown when the client invoke the remote call. This exception says class B cannot be serialized. But I only return the vector that is modified by class B to the client side, not any instance of class B.

What is wrong with it? It works fine with CORBA. But why Java RMI doesnt like it?

Thanks.
 
Edward Harned
Ranch Hand
Posts: 291
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post JUST the relavent portions of the classes so we can see what you're talking about.
 
Oricio Ocle
Ranch Hand
Posts: 284
Debian Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the vector being serialized, all it's elements must be too.
So if the vector contains a non serializable object, the vector can not be serialized.

Your problem seems to be that your vector constains instances of B.

As a aside note, passing o returning Collections in remote method is not a good practice.

Regards
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
passing o returning Collections in remote method is not a good practice.

Absolutely right! Send arrays - the Collections API has great methods for converting between arrays and Java collections.
Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!