473,394 Members | 1,739 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

User-defined classes and serialization

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
Jul 17 '05 #1
1 2275
Right well the problem was that I was writing "implements
Serializable" upon the derived class (PlayList) and not on
the base class (BaseContainer). Now it works just as it
should.

Mike

"Mike Frayn" <re**********@hotmail.com> wrote in message
news:40***********************@lovejoy.zen.co.uk.. .
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

Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

60
by: Fotios | last post by:
Hi guys, I have put together a flexible client-side user agent detector (written in js). I thought that some of you may find it useful. Code is here: http://fotios.cc/software/ua_detect.htm ...
3
by: zlst | last post by:
Many technological innovations rely upon User Interface Design to elevate their technical complexity to a usable product. Technology alone may not win user acceptance and subsequent marketability....
6
by: martin | last post by:
Hi, I am a web page and a web user control. My web user control is placed in my web page using the following directive <%@ Register TagPrefix="uc1" TagName="Header"...
1
by: Shourie | last post by:
I've noticed that none of the child controls events are firing for the first time from the dynamic user control. Here is the event cycle. 1) MainPage_load 2) User control1_Load user clicks a...
0
by: tony | last post by:
Hello! This is a rather long mail but it's a very interesting one. I hope you read it. I have tried several times to get an answer to this mail but I have not get any answer saying something...
2
by: rn5a | last post by:
Assume that a user control (MyUC.ascx) encapsulates 2 TextBoxes with the IDs 'txt1' & 'txt2' respectively. To use this user control in an ASPX page, the following Register directive will be...
1
by: Carlettus | last post by:
Dear All, sorry but I'm not sure if this is the right place to post my problem. I was using the following asp code to create users in Active Directory. Suddenly, and I don't know the reason, users...
0
by: rbukkara | last post by:
Hi, I have got the following error while trying to add a user in the LDAP Directory. javax.naming.NameNotFoundException: ; remaining name 'uid=vassila,ou=People,dc=cs,dc=uno,dc=edu' I have...
9
by: Gordon | last post by:
I want to add a feature to a project I'm working on where i have multiple users set up on my Postgres database with varying levels of access. At the bare minimum there will be a login user who...
14
by: chromis | last post by:
Hi, I've been trying to implement a more OOP oriented approach to dealing with user security on one of my websites, and I am trying to validate the user against an array of roles, however I am...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.