我需要将 bytearray 转换为 double。我正在使用
double dvalue = ByteBuffer.wrap(value).getDouble();
但是在运行时我得到 BufferUnderflowException 异常
Exception in thread "main" java.nio.BufferUnderflowException
at java.nio.Buffer.nextGetIndex(Buffer.java:498)
at java.nio.HeapByteBuffer.getDouble(HeapByteBuffer.java:508)
at Myclass.main(Myclass.java:39)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.hadoop.util.RunJar.main(RunJar.java:212)
我需要在这里更改什么?
最佳答案
BufferUnderflowException - If there are fewer than eight bytes remaining in this buffer
所以 value
必须少于 8 个字节。 double
是一个 64 位、8 字节的数据类型。
关于将字节数组转换为 double 时出现 java.nio.BufferUnderflowException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25736794/