I've got problem with my bytes array. I try to convert it to long , then to hex and show it as a toast. However I get java.nio.BufferUnderflowException. Here's my code :
public void onReceivedData(byte[] arg0)
{
String tag = null;
long tagValue = ByteBuffer.wrap(arg0).getLong();
tag = Long.toHexString(tagValue).toUpperCase();
}
Problem is at line :
long tagValue = ByteBuffer.wrap(arg0).getLong();
I looked for information about this exception but none of the answers was solution for my problem.
This is logcat:
Process: com.example.eltegps011.eltegps, PID: 17304
java.nio.BufferUnderflowException
at java.nio.ByteArrayBuffer.getLong(ByteArrayBuffer.java:211)
at com.example.eltegps011.eltegps.fragments.StocktakingFragment$9.onReceivedData(StocktakingFragment.java:504)
at com.felhr.usbserial.UsbSerialDevice$WorkerThread.onReceivedData(UsbSerialDevice.java:261)
at com.felhr.usbserial.UsbSerialDevice$WorkerThread.run(UsbSerialDevice.java:235)