Hello again,
Okay, I was reading the following tutorial on serialization
of user-defined classes, and it seems pretty
straightforward:
http://www.sys-con.com/story/?storyid=44199
That being said, I can't get it to work for me. There are
no exceptions generated when I read or write to the stream,
however the class that is read back in is completely empty.
Just to be sure, here is the (comments-removed) code as I've
taken from that tutorial:
public static void SavePlayListState() throws IOException
{
ObjectOutputStream ObjectStream = null;
FileOutputStream FileStream = null;
FileStream = new
FileOutputStream(arystrLocations[2]);
ObjectStream = new ObjectOutputStream(FileStream);
ObjectStream.writeObject(MainPlayList);
ObjectStream.flush();
ObjectStream.close();
FileStream.close();
return;
}
public static void RestorePlayListState() throws
ClassNotFoundException, IOException
{
ObjectInputStream ObjectStream = null;
FileInputStream FileStream = null;
FileStream = new
FileInputStream(arystrLocations[2]);
ObjectStream = new ObjectInputStream(FileStream);
MainPlayList = (PlayList)ObjectStream.readObject();
ObjectStream.close();
FileStream.close();
return;
}
---------
The class that I'm using is a derived class of
BaseContainer, all it has added was accessor methods to
access the fields within the m_Data member.
public class BaseContainer
{
protected ArrayList m_aryContainedData;
protected BaseContainerData m_Data;
private long m_lID;
static long m_lGeneratedIDs = 0;
public BaseContainer()
{
m_lID = BaseContainer.m_lGeneratedIDs++;
m_aryContainedData = new ArrayList();
}
public BaseContainerData GetData() { return m_Data; }
public long GetID() { return m_lID; }
}
Now, from what I've read regarding these serialization
processes, I only need to write a writeExternal() method if
I don't want certain values to be written out or if the
objects within my own class are not serializable, which I
believe they are.
So, the ArrayList is declared in the base class as is the
ContainerData itself (m_Data). When I deserialize the
class, I am getting told that the ArrayList is now empty and
the strings within m_Data are all null.
I have gone over the java sdk documentation and they seem to
be telling me that what I've done should work, but obviously
I'm missing something here. Can anyone give me a nudge in
the right direction?
Thanks,
Mike