views:

201

answers:

1

i am trying to create a mock shopping cart for a uni project. im using two java classes Item and shoppingCart, shopping cart uses a vector to store Items and then writes them to a file. i am trying to use the classes on a jsp page but when i try to write to the file i get an java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: cart.Item... any ideas how i could fix this??

+2  A: 

From the javadoc on NotSerializableException... "Thrown when an instance is required to have a Serializable interface."

This means that your class that you're serializing need to implement the Serializable marker interface.

Yuliy
You could add that it needs a 'serialVersionUID' in order to be Serializable.
boutta
i have tried implementing Serializable on both classes with no luck
Does Item contain any members that are not serializable? Otherwise, I'd double-check that you are indeed implementing java.io.Serializable.As for serialVersionUID, you should have that, but it won't result in NotSerializableException if you do not provide it (the runtime will auto-calculate the version ID when needed).
Yuliy