• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Updating a file from an object (ArrayList)

 
Liana Norpunova
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Camick's List Table Model may be of use.
http://tips4java.wordpress.com/2008/11/24/list-table-model/
 
Carlos Oliveira
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Liana Norpunova
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This topic is drifting further and further away from Swing / AWT / SWT / JFace.
 
Liana Norpunova
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20611
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you please post it here? That will also help others who come searching for similar problems.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic