• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Updating a file from an object (ArrayList)

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?



 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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/
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22682
128
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you please post it here? That will also help others who come searching for similar problems.
 
The world's cheapest jedi mind trick: "Aw c'mon, why not read this tiny ad?"
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic