• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need some help on Arrays  RSS feed

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi so im having a small problem that i cant figure out and its that everytime i try to run my code im getting an ArrayIndexOutOFBoundsException around lines 60 and 61 and im not sure how to fix this can anyone help me with this?
Thank you
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The basic format for iterating an array with a for loop is:-
for (int i = 0; i < myArray.length; i++) ...
That format will always visit every element of the array missing none out and will never overrun the bounds of the array however large or small it is. you should always start from that format and consider changes; if you use both myArray[i] and myArray[i + 1] you will need a change.
Now have a look at your lines 60 and 61 and see how you have written the for loops.
 
Greenhorn
Posts: 2
Eclipse IDE Java Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I noticed the formatting of your for loop on line 58
The maximum index for the array is 14 but the loop will set the count variable to 15 because of
I think if you get rid of the +1 you will get rid of your ArrayOutOfBoundsException because the loop will then run and terminate before count is set to 15.
 
Sheriff
Posts: 4289
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch, Elliot.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!