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??
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.
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!!
Joined: Nov 06, 2005
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.