wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Updating a file from an object (ArrayList) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Updating a file from an object (ArrayList)" Watch "Updating a file from an object (ArrayList)" New topic
Author

Updating a file from an object (ArrayList)

Liana Norpunova
Greenhorn

Joined: Aug 24, 2010
Posts: 23
Hi guys!

I have a problem with updating files. Below you may see the code. I want simply insert new row in the list "userDataList". This list is stored in the file and is used to fill JTable. When new row is insterted in the list, I would like to update the file and the table (this step is skipped so far). However, something is wrong in my code. As a result, I've got an error message shown below and my file has been filled with some random symbols.

Well, what could be my problem?



Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Rob Camick's List Table Model may be of use.
http://tips4java.wordpress.com/2008/11/24/list-table-model/


luck, db
There are no new questions, but there may be new answers.
Carlos Oliveira
Greenhorn

Joined: Sep 12, 2010
Posts: 7
Liana Norpunova wrote:Hi guys!

I have a problem with updating files. Below you may see the code. I want simply insert new row in the list "userDataList". This list is stored in the file and is used to fill JTable. When new row is insterted in the list, I would like to update the file and the table (this step is skipped so far). However, something is wrong in my code. As a result, I've got an error message shown below and my file has been filled with some random symbols.

Well, what could be my problem?




So that you can write the object using the method WriteObject, you need that your object is serializable, ie, implement the java.io.Serializable interface.

How do you not doing this is being released the exception java.io.NotSerializableException.

Try to refactor your code and then post your result!

I hope I helped!


"Java is able to generate more solutions and more problems than our 'vain' philosophy is able to provide!"
Liana Norpunova
Greenhorn

Joined: Aug 24, 2010
Posts: 23
Hi!

Thanks. I've implemented serialization in my code:

Now I don't get any error messages, however a random data is inserted in my file. Why does it happen?
Liana Norpunova
Greenhorn

Joined: Aug 24, 2010
Posts: 23
Well, I think I've understood my problem. I'm just using different methods to read/write the data (ArrayList) from/into file.

To read the data, I'm using the following code, which assumes that columns are separated with ",":


To write the date, I'm using ObjectOutputStream, which actually assumes different separators.



To solve the problem, I've tried using ObjectInputStream to read the data. But I've got that the System.out.println(listofusers.size()) = 0. Could someone explain me why does it happen? Thanks a lot.

Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

This topic is drifting further and further away from Swing / AWT / SWT / JFace.
Liana Norpunova
Greenhorn

Joined: Aug 24, 2010
Posts: 23
Hi!

I've solve this problem myself. If anybody will need a solution, just post me a message and I will share it. Thanks.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19653
    
  18

Could you please post it here? That will also help others who come searching for similar problems.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Updating a file from an object (ArrayList)
 
Similar Threads
how to use parseInt()
I/O with a DefaultTableModel object
How to convert arabic numbers received from JTextField to a Double?
nullPointerException on entity manager methods
? File I/O (and-or) for each loop