Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

writeObject() writes only one object from the vector  RSS feed

 
Estwood
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When user shuts the app. there is a vector containing some serializable objects created during the session and thay should be (writeObject()) saved to a text-file. The problem is that there is allways only one saved object in the file. I use an itarator to traverse the vector.
I would really appritiate if someone have some suggestion or perhaps solution for my problem.
Thank you all in advance.
[ January 09, 2002: Message edited by: Estwood ]
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since all the objects in the Vector are serialized, why not write the Vector object to the file instead?
 
Estwood
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Jason for you replay! Sometimes one consider data-structure as a "tool" and forget that it is an object to.
However, have you any idea why is it so that only one object from the vector ends upp in the file ?
[ January 09, 2002: Message edited by: Estwood ]
[ January 09, 2002: Message edited by: Estwood ]
[ January 09, 2002: Message edited by: Estwood ]
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not without looking at your code, sounds like you have something weird in your looping construct that's overwriting. You could always check before it starts writing what the last object of the Vector is and see if that is the one that is in the file. Any pattern to it?
Jason
 
Estwood
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seams that everything is ok with the "while-loop". It is standart loop:
Iterator iteratorData = myVector.iterator();
while(iteratorData.hasNext())
{
objOut.writeObject(iteratorData.getNext());
}
fileOut.close();
Before writing items to the file I chack tha size of the vector and print out all the possible items to and everything is fine.
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure, how are discovering there is only one object? I wrote up the following classes, just to give a test and example:

Everything works fine. I noticed in your code example you have getNext(). There is no such method for Iterator, so your code wouldn't compile. Guessing that is a typo.
Anyway, I know the code that I wrote is very simple and isn't the best (in.close() never gets called because an EOFException occurs before it), but perhaps it can help you find what in your code might be causing you to only see one object.
Jason
[ January 10, 2002: Message edited by: jason adam ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!