How to correct Arraylist index out of bounds for length error in Java
I am writing a program for school which acts as a cash register. I am asking for input for prices of items and playing them into an ongoing ArrayList until the user enters -1 or 0. 0 is to re-enter the previous price in case of mistake and -1 terminates the loop. I am getting the java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0 error when I try to run my code. I have to include a method called removeLastEntry(), which will remove the last price entered into the array upon a 0 being entered by the user. How can I ensure the array is populated and I am indeed removing the
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.