• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Array out of bounds

 
Karine Roy
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 781
Java Netbeans IDE Ubuntu
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 .
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic