Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Problem in writing hashtable to file system.

Reply
Thread Tools

Problem in writing hashtable to file system.

 
 
Chris Smith
Guest
Posts: n/a
 
      07-13-2004
M wrote:
> After I put the "... implements Serializable" stuff in my class,
> it still give me the same error...
>
> Anything I might done wrong?


Are you sure it's the same error? If so, then you probably still have
an old copy of the class file for WorkNature sitting around somewhere.

If the error is a little different, then it might be something else.
Specifically, I suspect you might be misunderstanding the relationship
between WorkNature and myJavaProgram; if WorkNature is an inner class,
you need to ask yourself if that's really necessary, and if so how to
handle that in serialization (do you make myJavaProgram serializable,
for example, or something else).

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
Reply With Quote
 
 
 
 
VisionSet
Guest
Posts: n/a
 
      07-13-2004

"M" <(E-Mail Removed)> wrote in message
news:cd19da$119r$(E-Mail Removed)...
> Hi All,
>
> I have problem in writing a hashtable to the file system
> and hope you can give me some hints. The problem is like
> this:
>
> My hashtable consists of a key of type "String" and the
> value is a object of a class WorkNature:
> class WorkNature {
> String responsible;
> Vector duties;
> }
>
> It seems that I can write data to the hashtable (myHashTable)
> but when I try to put it to the file system, there's some
> problem. The code I used was:
>
> void writeSysFile() {
> final String PHY_FILE = "d:/Work_Nature";
> try {
> ObjectOutputStream os =
> new ObjectOutputStream(new FileOutputStream(PHY_FILE));
> os.writeObject(myHashTable);
> os.close();
> } catch (Exception e) {
> System.out.println("writeSysFile: " + e.getLocalizedMessage());
> }
> }
>
> Error "writeFile: myJavaProgram$WorkNature" was displayed !
>


Change your code.
Do not catch Exception, catch only the subclasses that are thrown.
ie IOException etc. That's just good practise.
In your catch block, put:
e.printStackTrace() for more meaningful debugging info.

--
Mike W


 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      07-13-2004
On Wed, 14 Jul 2004 02:29:06 +0800, M wrote:

> Woo, that's totally too technically for me!


...hhhmmmm.. What John and Chris said in relation
to that comment was alot more useful, but less funny,
than what I would have responded.

Maybe it is best they got to it first.

> Any clue? Thanks.


I take you back to..
<http://www.physci.org/codes/javafaq.jsp#exact>

Which, given it was written by me, pretty
much sums up the best advice I can muster
on general tips for solving exceptions.

There is a group that might be better for you
at this stage. A group where folks are a great
deal more patient and helpful..
<http://www.physci.org/codes/javafaq.jsp#cljh>

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      07-13-2004
On Wed, 14 Jul 2004 02:44:39 +0800, "M" <(E-Mail Removed)> wrote
or quoted :

>Thanks. But I'm new to Java and never heard about Serializable...
>The Java API doc is too complicated to me.. Do you mind
>give me some brief explanation?


see http://mindprod.com/jgloss/serialization.html

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
M
Guest
Posts: n/a
 
      07-14-2004
Thanks for the info. Especially the tips/solves...
I might jump into it often.

"Andrew Thompson" <(E-Mail Removed)> wrote in message
news:811t769vcs14$(E-Mail Removed)...
> On Wed, 14 Jul 2004 02:29:06 +0800, M wrote:
>
> > Woo, that's totally too technically for me!

>
> ..hhhmmmm.. What John and Chris said in relation
> to that comment was alot more useful, but less funny,
> than what I would have responded.
>
> Maybe it is best they got to it first.
>
> > Any clue? Thanks.

>
> I take you back to..
> <http://www.physci.org/codes/javafaq.jsp#exact>
>
> Which, given it was written by me, pretty
> much sums up the best advice I can muster
> on general tips for solving exceptions.
>
> There is a group that might be better for you
> at this stage. A group where folks are a great
> deal more patient and helpful..
> <http://www.physci.org/codes/javafaq.jsp#cljh>
>
> --
> Andrew Thompson
> http://www.PhySci.org/ Open-source software suite
> http://www.PhySci.org/codes/ Web & IT Help
> http://www.1point1C.org/ Science & Technology



 
Reply With Quote
 
M
Guest
Posts: n/a
 
      07-14-2004
Well, I have added "implements Serializable" to the class WorkAround.
But I haven't put "implements Serializable" to the calling class.

Is it necessary?

"Chris Smith" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed).. .
> M wrote:
> > After I put the "... implements Serializable" stuff in my class,
> > it still give me the same error...
> >
> > Anything I might done wrong?

>
> Are you sure it's the same error? If so, then you probably still have
> an old copy of the class file for WorkNature sitting around somewhere.
>
> If the error is a little different, then it might be something else.
> Specifically, I suspect you might be misunderstanding the relationship
> between WorkNature and myJavaProgram; if WorkNature is an inner class,
> you need to ask yourself if that's really necessary, and if so how to
> handle that in serialization (do you make myJavaProgram serializable,
> for example, or something else).
>
> --
> www.designacourse.com
> The Easiest Way to Train Anyone... Anywhere.
>
> Chris Smith - Lead Software Developer/Technical Trainer
> MindIQ Corporation



 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      07-14-2004
On Wed, 14 Jul 2004 09:48:37 +0800, "M" <(E-Mail Removed)> wrote
or quoted :

>Well, I have added "implements Serializable" to the class WorkAround.
>But I haven't put "implements Serializable" to the calling class.


see http://mindprod.com/jgloss/serializable.

You only need it on the objects you want to output, or the objects
they point to.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
Chris Smith
Guest
Posts: n/a
 
      07-14-2004
Andrew Thompson wrote:
> There is a group that might be better for you
> at this stage. A group where folks are a great
> deal more patient and helpful..
> <http://www.physci.org/codes/javafaq.jsp#cljh>


For the most part, pretty much the same people follow both groups, in my
experience.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
Reply With Quote
 
Chris Smith
Guest
Posts: n/a
 
      07-14-2004
M wrote:
> Well, I have added "implements Serializable" to the class WorkAround.
> But I haven't put "implements Serializable" to the calling class.


I don't know, mainly because I don't know what class WorkAround is. It
doesn't seem to have any relation to any of the relevant classes at all,
so chances are it doesn't need to be serializable.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      07-14-2004
On Tue, 13 Jul 2004 20:51:33 -0600, Chris Smith wrote:
> Andrew Thompson wrote:
>> There is a group that might be better for you
>> at this stage. A group where folks are a great
>> deal more patient and helpful..
>> <http://www.physci.org/codes/javafaq.jsp#cljh>

>
> For the most part, pretty much the same people follow both groups, in my
> experience.


Yes, but AFAIAC, it's smart questions or
merciless ridicule on c.l.j.programmer.
OTOH, When I post to c.l.j.h., I take
more care to be 'patient and helpful'.
Some others do as well.

The difference is not the *names* of the
people, but the 'way they hold their faces'
when answering questions.

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: hashtable or map? (map inserts not behaving as I expect - and I cant find a decent simple example for hashtable) Kai-Uwe Bux C++ 1 12-21-2008 09:25 PM
Hashtable problem =?Utf-8?B?QUQ=?= ASP .Net 6 02-25-2005 10:49 PM
Any problems with writing the information into a file - Multi-users perform writing the same file at the same time ???? HNguyen ASP .Net 4 12-21-2004 01:53 PM
Problem with hashTable Guillermo Perl 1 03-04-2004 12:43 PM
hashtable problem Ralf Bednarz Java 5 07-17-2003 09:36 PM



Advertisments