I am trying to send a Deck object that I have created by subclassing the Vector class through a TCP/IP Connection...I'm not sure if i'm doing this correctly, however...the problem isn't getting the deck SENT, i don't think, but receiving it correctly is the problem...

I can't seem to fix it...it might help to know if where the problem is rising...is it the WAY that i'm sending the object (basically, CAN I DO IT THAT WAY????)...or does it have to do with something else?...

any help is appreciated...even suggestions on how to fix it (sample code is *always* welcome...) ...

if i'm not sending the object in the correct manner, what is the best (easiest, even) to send one object from one machine to another?...

it says the exception is coming from javax.swing.Jcomponent...a Deck object is basically a subclass of a Vector (perfectly serializable, btw)...the Deck contains any number of Card objects...Cards are basically just subclasses of a JButton...now, a JButton is a JComponent, so I'm pretty sure that the problem lies within that class...however, I'm not sure how serialization works with hierarchy...

in order to make the classes compatible, i have set the serialVersionUID in both the Deck class and the Card class...

(...Deck...)static final long serialVersionUID = -8436333800348538015L;

(...Card...)static final long serialVersionUID = -8293881053128968132L;

as you can see, those SVUIDs aren't either of the ones described in the exception...

does anyone have a clue as to what I should do to fix this problem???...has anyone run into this before?...

When you serialize an object every member within that object is also serailized, and each of any members objects are serialized, and so on. The way to prevent this is to mark a member as 'transient' this means it will not be serialized and therefore will not be in your data you send across the wire. e.g.

public ArrayList a = new ArrayList(); public transient ArrayList b = new ArrayList();

The deserialized object ArrayList a will have all the contents from the original object, but b will be empty even if the serialized class had data there.

Clearly you are trying to deserialize something thats not the same between each JVM (either by your own classes or JVM version). I'd suggest starting near the top and narrowing as you go making objects transient to try to isolate the problem.

In general, NONE of the gui classes are serializable. Many AWT classes are inherently non-serializable (I've heard before that this is because, under the hood, they contain references to things like your local graphics memory; Sun could still have created a workaround, but apparently haven't). Nearly all Swing classes have for a while come with the comment (written in the docs for every class - have you READ the docs for the classes you are using?) "blah blah this is NOT serializable between different VM versions and/or platforms...this will be fixed in a later version of swing blah blah etc".

In general, just never try to serialize a Swing class. Although I do feel your pain - sometimes (though I very much doubt this is the case for you) you have to serialize gui classes. However, why on earth do you want to send a Button over the network? Just obey the M/V/C architecture (simple concept: separate your data (Model), display (View) and mouse-handling etc (Controller) - M,V,C. Read the Swing docs for info) and make a Model class representing the underlying data of your cards, and send that.

Have it DISPLAYED both ends by a separate class (a View, from the M/V/C terminology).

If this isn't clear, let me know and I'll try again; been awake almost 20 hours, and I'm not thinking too straight .

OK...so, I've managed to get the Deck successfully deserialized...that's the good news...

the bad news...is that I had to be using the same version of the JVM on both sides (precisely as all of you had implied)...and that's not taking advantage of the platform independency that java is used for...SO...I will be taking the advice of mr. blahblahblahh and using the M/V/C technique...

I guess i had to learn the lesson of swing serialization the hard way...

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org