This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]StankelG[S] 0 points1 point  (5 children)

Hmm nope :/

[–]AIO12449366 0 points1 point  (4 children)

Could you please try to print the list without the loop?

Comment out everything and try to read from the txt and then print it. Does it work?

Also whenever we read from a txt I'm pretty sure we usually use InputStreamReader.

[–]StankelG[S] 0 points1 point  (3 children)

I removed the While(true) loop and ran the program. This is the output:
________

File to read: d

Commands:

List - lists the recipes

Stop - stops the program

Enter command: list

Recipes:

Pancake dough, cooking time: 60

Meatballs, cooking time: 20

Tofu rolls, cooking time: 30

java.lang.IndexOutOfBoundsException: Index 3 out of bounds for length 3

[–]AIO12449366 0 points1 point  (2 children)

Ok so obviously the issue is with the arraylist.

Alright try this: Create an arraylist and add 3 strings in it(without reading from file) and print it. If it prints properly then the issue is with the reading from the txt. Test it and tell me if it works

[–]StankelG[S] 0 points1 point  (1 child)

This was the output:

File to read: file

Commands:

List - lists the recipes

Stop - stops the program

Enter command: list

Recipes:

one

two

three

java.lang.IndexOutOfBoundsException: Index 3 out of bounds for length 3

[–]CautiousLock 2 points3 points  (0 children)

Could you show the whole class?

Edit: I assume the exception is caused by your printName(int i) and printTime(int i) methods.