• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Errors when reading and writing from a text file - any help!!

 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm currently writing a test main class for a BorrowerList and Borrower class. Within the main class, I need to be able to read and write to a file, so users can add details about borrowers such as name, telephone number etc.

I am currently able to save one borrower to the file, but I am then unable to read the file back, as it reports an error of,



Strangely enough, if I then manually edit the text file and remove the membership number and borrower limit, which are both integers, from the start of the line in the text file, it will then allow further borrowers to be added.

Then, the problem becomes that the test main class still doesn't save the value for the membership number or the borrower limit, which the user has input using the keyboard. Instead, it just saves '0 0'.

I am really lost as to why this might be happening. Any ideas??

My code so far is as follows,

1. Main class for testing the other classes,



2. BorrowerList class,



Any help or advice would be gratefully appreciated!!
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's hard to say what happens during I/O, because the Borrowers.saveTo method is not shown. A first step might be to ascertain that the values actaully are entered correctly, by printing them out before saving.
 
celine scarlett
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

The Borrower class saveTo method saves the following,



where the getForename(), getSurname(), etc methods are inherited from a Person class. The Borrower class simply extends the Person class.

Any idea why the main class, as listed in the original thread, would save only the strings and not the integers?

Any help or advice really appreciated!!
 
celine scarlett
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm very glad to say that the problem has now been solved. I was declaring two method variables within the Borrower class constructor, and not allowing the value to actually reach the variable in that constructor, as specified in the previous class constructor.

Thanks to everybody for their help.

Have a great weekend!!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic