Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ArrayIndex OutOf Bounds Exception

 
Harish Maridi
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am getting ArrayIndexOutOfBoundException. Code that generating this exception is

it is showing that exception is at last line of the code block.
I am facing difficulty to find out the cause of exception.
Please help me regarding this.
Thanks in advacne
-mark
 
arunkumar subramanian
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark

I think your FOR loop hits the end of Array

Try

for(int i=0;i < al1.length;i++){

Hope this helps
 
Robin Lane
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by arunkumar subramanian:
Hi Mark

I think your FOR loop hits the end of Array


He's right, Mark. Remember, array indices start at zero. So, the length of your array is 14 but has index numbers of 0 - 13. Therefore, your counter (i, in your code) must be less than, not equal to or less than, the array length.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic