my dog learned polymorphism*
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
Author

Array out of bounds

Karine Roy
Greenhorn

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(Parts.java:25)
at Parts.main(Parts.java:13)

Here is the code I have so far:



Can someone please help me?

Thanks!
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: http://aspose.com/file-tools
 
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??