A J2SE/ Android Complication


#1

Hi, everybody,

I created JSSE application that uses a serializable class named StoryNode. This ‘StoryNode’ class needs only the java.io.* import statement. The class that uses this ‘StoryNode’ class has a Vector object that holds the the ‘StoryNode’ objects. This Vector object is serialized to a file(with a .str file extension) which another Android application I wrote can read.

So I copy this file to the assets directory of my android project. I can get an Inputstream to the file from within an Activity class with the following code:
InputStream in = getAssets().open(“astorytree.str”);

But there’s a problem. In the android application when I try to deserialized the inputstream to a Vector object an exception is thrown saying: java.lang.ClassNotFoundException: StoryNode

Within my android project I have already defined the StoryNode class, so I don’t understand why the StoryNode class can’t be found. Even though android uses the Dalvik virtual machine, its still the JVM that’s there(I think) so I don’t know if there is some incompatibility with a class defined using pure J2SE and the very same class defined in an android project.

Thanks in advance.


#2

How do you deserialize? Have a look at the code below…
StoryNode st = ( StoryNode ) loadObjectFromFile("filename.str") ; private static synchronized Object loadObjectFromFile(String filename) { Object obj = null; File recFile = new File(filename); if (recFile.exists()) { try { ObjectInputStream ois = new ObjectInputStream(new FileInputStream(recFile)); if (ois != null) { obj = ois.readObject(); } } catch (IOException ex) { // } catch (ClassNotFoundException ex) { // } } return obj; }