Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Array IndexOutOfBounds Exception

 
unyime inok
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how do i fix this please?
java.lang.ArrayIndexOutOfBoundsException: 50
at IntFile1.readInteger(IntFile1.java:54)




 
Jeff Bosch
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I noticed that when you assign the array element, you're not checking the array bounds. I recommend checking that x is less than the length of your array before assigning a value to an array element with index x. That should fix your problem.
 
Jeff Bosch
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In other words, instead of


I would use:



There are better ways to do this, but this solution at least checks the array bounds to make sure you don't exceed the array length.
[ November 10, 2004: Message edited by: Jeff Bosch ]
 
unyime inok
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot. i'll try doing that.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic