I've got a NotSerializableException
, and the jvm is telling me it is coming from a class that has absolutely nothing to do with what is getting serialized to the ObjectOutputStream
!
What on earth could be going on? The class it mentions as the problem is NOT serializable, and manipulates some data from OTHER classes which most definitely ARE serializable, why on earth would this result in a NotSerializableException
?
EDIT: Please dont vote down this is a serious question! Ok, so i'm just wondering whether the following could be a problem: If i had an anonymous arraylist, being inserted into a map, (which most definitely IS serializable), in a class which is NOT serializable, could this be the problem????
like so: map.put(new ArrayList(){{add(ect....}});
Fields also have to be Serializable. A gotcha is that nested classes have a reference to their outer class.
class NotSerializable {
class Inner implements Serializable {
// contains a reference to this$0, the outer instance
}
}
i.e. you have a field you might not be aware of.
The simple solution is to make the inner class static