cole
cole

Reputation: 3357

java.lang.IndexOutOfBoundsException: index=3 out of bounds (limit=6, nb=4)

My Code

ByteBuffer bb = ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN);
bb.getDouble())

I am trying to pass Uint24 containing 2 bytes into a variable using above code. But it crashes giving me error

java.lang.IndexOutOfBoundsException: index=3 out of bounds (limit=6, nb=4)

For single byte I am using short like bb.getShort();

Please someone could explain me on how to do it.

Upvotes: 2

Views: 1774

Answers (2)

maqsats
maqsats

Reputation: 358

This error could be caused by the corrupted font.

Upvotes: 3

Hovanes Mosoyan
Hovanes Mosoyan

Reputation: 760

  1. Let's note: the getDouble() tries to read eight bytes at the current index, so perhaps there aren't so much data in the array (limit=6).

  2. I think we should use the asIntBuffer() (https://docs.oracle.com/javase/7/docs/api/java/nio/ByteBuffer.html#asIntBuffer()) in yours case.

Bests )

Upvotes: 0

Related Questions