This content has been marked as final. Show 2 replies
When things go wrong with reading data it's a good idea to print out on the console exactly what the program is "seeing".
This will let you check that that doLoad() is being executed at all and the values that are being used to create the new booking. Your code is, in fact, creating a new instance of Booking and adding a reference to that instance to the bookings array. (providing it is being called at all...).
selectedUnit = scan.nextInt(); // Rows of the array selectedDay = scan.nextInt(); // Coloumns of the array String text = scan.nextLine(); // First part of string in cell String number = scan.nextLine(); // Second part of string in cell System.out.println("selectedUnit=" + selectedUnit); System.out.println("selectedDay=" + selectedDay); System.out.println("text=" + text); System.out.println("day=" + day);
If the data being read is not what you expect then you have things to check: the actual contents of the file, and the detailed descriptions of what the scanner methods do.
If the data being read is what you expect, then you have to get precise about what you mean by "no data is entered into the array" and find out why that is happening. (eg some other code is removing the reference from the array, or changing the value of bookings etc).
It occurs to me that I might not have been clear about what it is to be precise about "no data is entered into the array".
Basically it will be a statement of the form "I run <insert code> expecting to see <insert good behaviour> instead I observe <insert bad behaviour>".
(The order of things I would follow is as given in the post: first check the file contents because that's easy, then check the scanner behaviour because problems with nextInt()+nextLine() are common. Only then consider the trickier question of why an array - later on - does ot have the contents I think it should.)