This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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.
 
Don't get me started about those stupid light bulbs.
 
subject: ArrayIndex OutOf Bounds Exception
 
Similar Threads
Remove duplicates in arraylist
Cloning Doubt
Java Mail
javax.mail package
Printing using Runtime.getRuntime().exec()