The problem is likely here in your decodeMessage
method. I've snipped out some code to isolate the problem:
int[] digit = new int[3];
while (!nullReached)
{
for (int i = sampleIndex; i < sampleIndex + 3; i++)
{
if (i < samples.length)
{
digit[i] = getDecimalDigit(samples[i].getValue(), 0); // This should be the line that throws the exception
}
}
sampleIndex += 3;
}
The second time through your while
loop, sampleIndex
will be 3
, so i
will start at 3
. Then you try to dereference digit[i]
, which would be digit[3]
. Since digit[]
is an int[3]
, then digit[3]
is out of the bounds of the array.
Maybe you want to do this instead:
digit[i-sampleIndex] = getDecimalDigit(samples[i].getValue(), 0);