Serializing and exporting/saving objects
in
Programming Questions
•
3 years ago
Hey
I found this old post from "drdoe" at the old forum (published four years ago) and was wondering the same thing - apart from the Boids part. Anyone know if you can serialize in a way that makes the RegisteredMethods become serialized or skipped or something that makes me serialize my own class? Is the question obsolete? Am I missing something obvious?
I was thinking about why it becomes a problem and the current guess is that as long as I have any methods from PApplet in my class, the class will not serialize at all. (?)
It is not a major issue for me even if it would be a wonderfully convenient (and data safe) way to save some data.
All the best
/JohanW
http://visualinformation.org
I found this old post from "drdoe" at the old forum (published four years ago) and was wondering the same thing - apart from the Boids part. Anyone know if you can serialize in a way that makes the RegisteredMethods become serialized or skipped or something that makes me serialize my own class? Is the question obsolete? Am I missing something obvious?
I was thinking about why it becomes a problem and the current guess is that as long as I have any methods from PApplet in my class, the class will not serialize at all. (?)
It is not a major issue for me even if it would be a wonderfully convenient (and data safe) way to save some data.
Anyone got any insights in this?I've got a sketch with a some class instances I'd like to export (basically, it's an evolution-simulation with a population of boids). All the involved classes implement Serializable, and java.io.* is imported for the entire sketch.
However, I get the following error:
java.io.NotSerializableException: processing.core.PApplet$RegisteredMethods
(I got a different notSerializable-exception when I used OpenGL, but OpenGL isn't really necessary in this situation [neither is P3D]).
I've got the following code (all in seperate try-catch blocks):
f_out= new FileOutputStream("winner.data");
ObjectOutputStream obj_out = new ObjectOutputStream (f_out);
obj_out.writeObject ( boid[0] ); // the exception above is thrown here
the boid[0]-instance is the boid with the best fitness after x generations, and that class instances some other classes of my own making, but as I mentioned, they all implement Serializable.
Soooo what do I do?
All the best
/JohanW
http://visualinformation.org
1