0

So, i have a class which has the following attributes

private String name;
private int counter;

private DateFormat df;
private DecimalFormat def;

private ArrayList<Bike> bike;
static String[] titles = {"some,items,here"};

all these are already initialized and then on top i declared public class Motor extends AbstractTableModel implements Serializable but i still get a IONotSerializableException when i use an ObjectOutputStream, is there some restrictions which i might now know that's why its like this?

acvon
  • 161
  • 3
  • 6
  • 21
  • Does `AbstractTableModel` have any non-serializable members? For example, have you added listeners that do not implement `Serializable` or `Externalizable`? Is `Bike` serializable? – Mike Samuel May 19 '11 at 04:08
  • 1
    Oh, and putting `Bike`s inside your `Motor` is a violation of object-oriented principles. The `Motor` should contain a `HamsterWheel` which contains a `Hamster`, and everyone knows hamsters can't ride `Bike`s. – Mike Samuel May 19 '11 at 04:11
  • Mike, no worries on the violation as its something else but not exactly that. On the side note, the AbstractDataModel is used as a tablemodel for my JTable, I'm not sure whether those have any non serializable members. But, asides the motor issue, am i doing something wrong here which serializable couldn't be implemented? – acvon May 19 '11 at 05:00

1 Answers1

0

All of those fields is serializable, with the possible exception of Bike.

So that means that:

  • Bike is not serializable. Or possibly it is serializable but one of the actual bike object's fields is not fully serializable.
  • There is some other non-serializable field of Motor that you've not shown us.
  • AbstractTableModel or its superclasses have non-serializable fields.

The exception message and full stacktrace should give clues to the real source of the problem.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • java.io.NotSerializableException: com.apple.laf.AquaPainter$DirectOSXSurfacePainter at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1164) at – acvon May 19 '11 at 12:17
  • Well that's fairly obvious ... It is telling you that it is trying to serialize some GUI framework object (class name given in exception message). Now you have to figure out where in *your* classes there is a reference to one of those objects, or some object that refers to them. Look for references to GUI framework objects in general -- they shouldn't be serialized and should be declared as `transient` to prevent this. – Stephen C May 19 '11 at 22:27