This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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
Similar Threads
Array out of bounds
Write a method that can be called, that will initialize the seating plan.
Datatype casting. Split Strings to double 2D array. (loss of precision)
Compile issue -- misplaced construct error
Tokens into array, datatype??