Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

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

 
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...
 
Bartender
Posts: 1845
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 :-)

>
 
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?"
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic