File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes I/O and Streams and the fly likes Array out of bounds Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Array out of bounds" Watch "Array out of bounds" New topic

Array out of bounds

Karine Roy

Joined: Jul 11, 2011
Posts: 13
I am new at Java and I am not sure if I am posting at the right place. Please let me know if I am not. I am trying to transfer a 2 dimension array to a text file but get the following runtime error:

java.lang.ArrayIndexOutOfBoundsException: 2
at Parts.writeArray(
at Parts.main(

Here is the code I have so far:

Can someone please help me?

James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

The problem is due to the fact that your 2D array is not 'square' but the inner loop in this pair

assumes it is square. It is easily rectified. You just need to make sure that the inner loop indexes over the length of the row being processed i.e. parts[row].length and not parts.length .

Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
I agree. Here's the link:
subject: Array out of bounds
It's not a secret anymore!