Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

ArrayIndexOutOfBoundsException: 0 error  RSS feed

 
thomas lim
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I got this error: "ArrayIndexOutOfBoundsException: 0". Can anyone tell me how to solve it?
 
Junilu Lacar
Sheriff
Posts: 11477
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't use formatting tags inside code tags. Reference the line number instead. I assume line 17 is where the exception is happening.
 
Junilu Lacar
Sheriff
Posts: 11477
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would solve it by making sure that the array variable has a length that's at least equal to moduleno.
 
Carey Brown
Saloon Keeper
Posts: 3310
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thomas lim wrote:I got this error: "ArrayIndexOutOfBoundsException: 0". Can anyone tell me how to solve it?

If array[i] throws and exception when i==0 then you have not allocated sufficient (or any) memory to hold the array contents.

You don't show the code where you are declaring and initializing "array". I might guess that you have something like:
rather than, for example
 
Campbell Ritchie
Marshal
Posts: 56530
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:. . . . I might guess that you have something like:
. . .
Will that actually compile?
 
Carey Brown
Saloon Keeper
Posts: 3310
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:
Carey Brown wrote:. . . . I might guess that you have something like:
. . .
Will that actually compile?

Good catch. No, it won't compile. But this will

I don't know what the OP is really doing because he hasn't shown us that bit of code.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!