• Post Reply Bookmark Topic Watch Topic
  • New Topic

java.lang.ArrayIndexOutOfBoundsException: 50 at main.main(main.java:107)  RSS feed

 
pulkit bahl
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am getting java.lang.ArrayIndexOutOfBoundsException: 50 at main.main(main.java:107) which is normally due to arrays not declared or defined properly but i m unable to debug it please help...
 
Stefan Evans
Bartender
Posts: 1837
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Line 107 relates to this line:


There are two array references here, and thus two potential array index out of bounds exceptions.
So either x has a value outside the range allowed for the num array
or i has a value outside the range allowed for the UserIDListUser array?

Which do you think it is?


Here is a short compilable and runnable example to help you debug your problem.




Can you spot it now?

In terms of making your code easier to write/debug I would suggest things like
- breaking your code up into methods to make each bit easier to understand and test
- follow standard naming conventions for Java programming - such as using a lower case letter to start a variable name.  It makes it easier to read for us experienced programmers, and more likely you will get an answer here :-)

>
 
Julian West
Ranch Hand
Posts: 91
3
Chrome Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pulkit bahl wrote: java.lang.ArrayIndexOutOfBoundsException ... which is normally due to arrays not declared or defined properly

This is not entirely correct.  This error is telling you that you are trying to access an array index that is outside the range of the array.

Hence, the questions to ask are, "What is the index I am using?" and "What is the range of the array that I am accessing?"
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!