wood burning stoves 2.0*
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
Author

ArrayIndex OutOf Bounds Exception

Harish Maridi
Ranch Hand

Joined: May 20, 2008
Posts: 60
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

Joined: Jun 10, 2008
Posts: 32
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

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: http://aspose.com/file-tools
 
subject: ArrayIndex OutOf Bounds Exception