File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes ArrayIndex OutOf Bounds Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "ArrayIndex OutOf Bounds Exception" Watch "ArrayIndex OutOf Bounds Exception" New topic

ArrayIndex OutOf Bounds Exception

Harish Maridi
Ranch Hand

Joined: May 20, 2008
Posts: 60

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
arunkumar subramanian
Ranch Hand

Joined: Jun 10, 2008
Posts: 32
Hi Mark

I think your FOR loop hits the end of Array


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

Hope this helps
Robin Lane
Ranch Hand

Joined: Apr 30, 2008
Posts: 76
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.

Disclaimer: The author of this post makes no claims, implied or otherwise, as to her ability to understand anything but the simplest of answers. Further, the author of this post has no programming background whatsoever and has taken one Java Programming class which was 9 weeks long. She does want to learn, so please teach patiently.
I agree. Here's the link:
subject: ArrayIndex OutOf Bounds Exception
It's not a secret anymore!