I have a class as follows:
final ByteBuffer data;
1st_constructor(arg1, arg2, arg3){
data = ByteBuffer.allocate(8);
// Use "put" method to add values to the ByteBuffer
//.... eg: 2 ints
//....
}
1st_constructor(arg1, arg2){
data = ByteBuffer.allocate(12);
// Use "put" method to add values to the ByteBuffer
//.... eg: 3 ints
//....
}
I created an an object from this class called "test":
I then created a byte[].
byte[] buf = new byte[test.data.limit()];
However, when I try and copy the ByteBuffer in the object to the byte[], I get an error.
test.data.get(buf,0,buf.length);
The error is:
Exception in thread "main" java.nio.BufferUnderflowException
at java.nio.HeapByteBuffer.get(Unknown Source)
at mtp_sender.main(mtp_sender.java:41)
Thank you for your help.