aspose file tools*
The moose likes Beginning Java and the fly likes ArrayIndexOutOfBound Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "ArrayIndexOutOfBound" Watch "ArrayIndexOutOfBound" New topic
Author

ArrayIndexOutOfBound

khurram babar
Greenhorn

Joined: May 13, 2003
Posts: 4
any body tell me when this occurs plz tell me with brief description
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

I believe this occurs when you try and access an array element that does not exist. For example, say you had:
String[] i = {"Gregg", "Henry", "Jo"};
and then you said:
String name = i[3];
You would probably get that error because element 3 is "out of the array bounds".


GenRocket - A Test Data Generation Platform
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

an ArrayIndexOutOfBoundsException happens when .... ummmm.. you're accessing an array and you go out of bounds (helpful huh? )
But no, seriously -- that's exactly what happens.
Lets say you have a snazzy li'l int array that holds 5 ints like this:
int intArray[] = {0, 1, 2, 3, 4};
(now remember -- arrays start at index 0)
So... if I try to access spaces 0 thru 4, everything's fine -- no problems -- there are numbers in all those spots, and all those spots actually EXIST.
System.out.println( intArray[0] );
System.out.println( intArray[1] );
System.out.println( intArray[2] );
System.out.println( intArray[3] );
System.out.println( intArray[4] );
But what happens if I try to access BEYOND that last spot?
System.out.println( intArray[5] );
*boom* ArrayIndexOutOfBoundsException
get it?
So... what do you think will happen if you try to access a negative index? like this:
System.out.println( intArray[-1] );


- Jess
Blog:KnitClimbJava | Twitter: jsant | Ravelry: wingedsheep
jim gotti
Ranch Hand

Joined: Jul 02, 2002
Posts: 36
the ole +1 -1 error. remember array indecies(spelling?) run from 0 to n-1, where n is the length of the array at creation.
So as the above posters pointed out....
an array of length say 5, has indecies from 0 to 4 (n-1)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ArrayIndexOutOfBound
 
Similar Threads
How to run Servlet program on Eclipse.?
5 to 10 line coding Qs in SCJP.
Borders
when i use float gg =10f;// flaot gg = 10;
How is I-Flex solutions,Mumbai?