2

I'm trying to save an object that has an ArrayList of Connector, which is a class that extends Path2D.Double. It gives me the exception gui.Connector; no valid constructor. I did a little research and came across this:

no valid constructor when serializing a subclass of Path2D.Double

It gave me a fine explanation, but no workaround. Is there a way I can desserialize a subclass of Path2D.Double?

  • Can you wrap the `Path2D.Double` within the `Connector` class...in other words do you need to use _inheritance_ (eg what behavior do you need to override in the Path2D.Double class)? – copeg May 08 '15 at 17:15
  • You're right... I did not need to use inheritance in this case. But still, if I wrap it, will it deserialize? – Marco Aurélio May 08 '15 at 17:20
  • It worked, @copeg ! Thanks for pointing that out. May you post it as an answer so I can mark it as the right one? – Marco Aurélio May 08 '15 at 17:29

1 Answers1

0

The Path2D.Double can be serialized/deserialized without issue (it has access to the Path2D no-arg constructor). If you do not need to override the behavior of Path2D.Double, you can have an instance of this class as a field in your Connector class (rather than have Connector extend the Path2D.Double).

copeg
  • 8,290
  • 19
  • 28