• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
celine scarlett
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • 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!!
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic