'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.



Solution 1:[1]

This error could be caused by the corrupted font.

Solution 2:[2]

  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 )

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 prsnlme
Solution 2 Hovanes Mosoyan