我在其中JNI本機函數需要短[]參數的Android項目中使用JNI代碼。但是,原始數據存儲爲ByteBuffer。我試圖按照以下方式轉換數據格式。如何從ByteBuffer獲得short []
E/AndroidRuntime(23923): Caused by: java.lang.UnsupportedOperationException
E/AndroidRuntime(23923): at Java.nio.ShortToByteBufferAdapter.protectedArray(ShortToByteBufferAdapter.java:169)
任何人都可以建議執行轉換的裝置:
ByteBuffer rgbBuf = ByteBuffer.allocate(size);
...
short[] shortArray = (short[]) rgbBuf.asShortBuffer().array().clone();
但是運行上面所示的第二行代碼時,我會遇到以下問題?
你能解釋一點,爲什麼使用allocateDirect()?因爲我沒有從android文檔中找到任何提示。 – bei 2012-08-13 08:54:38
這是基於提交的[錯誤報告](http://code.google.com/p/android/issues/detail?id=24327)的預感。這可能是無關的,但我認爲這值得一提。 – Eric 2012-08-13 18:06:34
我收到與此相同的錯誤。 – 2014-10-10 12:08:25