Forums Register Login

ArrayIndexOutOfBoundsException: 0 error

+Pie Number of slices to send: Send


I got this error: "ArrayIndexOutOfBoundsException: 0". Can anyone tell me how to solve it?
+Pie Number of slices to send: Send
You can't use formatting tags inside code tags. Reference the line number instead. I assume line 17 is where the exception is happening.
+Pie Number of slices to send: Send
You would solve it by making sure that the array variable has a length that's at least equal to moduleno.
1
+Pie Number of slices to send: Send
 

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
+Pie Number of slices to send: Send
 

Carey Brown wrote:. . . . I might guess that you have something like:
. . .

Will that actually compile?
+Pie Number of slices to send: Send
 

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.
And then the entire population worshiped me like unto a god. Well, me and this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 329 times.
Similar Threads
Unable to get desired output for Java GPA calculator
If else condition problem
For Loop - Integers stuck @ "0"
simple programming trouble
Actually I'm lost
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 05:03:40.