We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpIntegration › Loading serialized objects from Java in P5
Page Index Toggle Pages: 1
Loading serialized objects from Java in P5 (Read 1127 times)
Loading serialized objects from Java in P5
Nov 17th, 2005, 3:21pm
 
I wrote a simple Java program that records data from a network input to a serializable data structure that I created.  I know the structure is functioning properly, because I can reload the data successfully with the same program. But when I copy the source for the serializable object over to my Processing sketch,  and try to un-serialize data files created with the Java program within a P5 sketch, I get an invalid class exception.

However, I wrote a simple data recorder within P5, and that can record and playback its own data using the same .java file for the serializable structure, but the Java software can't load serialized output created by the P5 version.

The source for the serializable structure is identical in the Java and P5 versions, including the long defining the version, except that the Java version is in a package and the P5 version isn't.  What is going on here?
Re: Loading serialized objects from Java in P5
Reply #1 - Nov 17th, 2005, 6:04pm
 
i believe changing the package will hose serialization, since it's no longer the same "class".

also be mindful (i think you're doing this already) that the files need to be .java files (not just new tabs with the same name, which will create pde files) so that they don't get run throuhg the preproc and included as inner classes.
Re: Loading serialized objects from Java in P5
Reply #2 - Nov 17th, 2005, 7:59pm
 
Thanks for the feedback. I'll try it without the package and see if it helps. I think I had trouble when I initially went from the original prototype in p5 to the Java version, which initially wasn't in a package, but maybe I'm wrong. It was a couple of months ago, and very frustrating.

Is there a way to use an external class file in a p5 sketch? (ie, compile the class once, use it in both the P5 sketch and the java program)

And yes, it's still a .java. I do all my editing in JEdit, rather than the IDE.

Edited:
It might be easier, if such a thing is possible, to use the Net library within the java program that plays back and records the serialized data to talk to the P5 sketch that acts on that data.  Can a p5 library be used in non-p5 java code?  I also need to send data to MAX via MAXLink from the same data source, so figuring that out would be useful eventually..
Re: Loading serialized objects from Java in P5
Reply #3 - Nov 18th, 2005, 5:02pm
 
if you have class files in a jar, add the jar file to the sketch (under the sketch menu) and it'll place it in a folder called "code", which will then be added to your program each time it's run.

this is probably a better way of dealing with it than trying to make sure that things compile the same way in both places, because the compilers, target settings, source settings, etc will all be different, and likely to give you trouble between the two setups.
Page Index Toggle Pages: 1