Great. Thank you very much. On 12月17日, 上午6时20分, fadden <[email protected]> wrote: > On Dec 16, 9:05 am, "William.lw.w" <[email protected]> wrote: > > > When I run it, it report below error: > > 12-16 23:49:54.307: WARN/dalvikvm(653): JNI WARNING: method declared > > to return 'Ljava/nio/ByteBuffer;' returned 'Ljava/nio/ > > ReadWriteDirectByteBuffer;' > > 12-16 23:49:54.307: WARN/dalvikvm(653): failed in Lcom/lw/ > > mupdf/PdfViewer;.readPage ('Ljava/nio/ByteBuffer;' not found) > > > What's the meaning of "failed in Lcom/lw/mupdf/PdfViewer;.readPage > > ('Ljava/nio/ByteBuffer;' not found)? And how to solve it? > > The JNI checks are trying to ensure that the type of object you're > returning matches up with what the method was declared to return. In > this case, a direct byte buffer is a ByteBuffer, so it should succeed. > > The problem is that the class lookup on java.nio.ByteBuffer failed. > The CheckJNI code is assuming that ByteBuffer must already be loaded, > which is a reasonable assumption since loading a class will pull the > superclasses in. ReadWriteDirectByteBuffer extends DirectByteBuffer > extends BaseByteBuffer extends ByteBuffer. > > As it turns out, the CheckJNI code is mildly broken, in that it > assumes the class has been loaded *by the current class loader*, which > for JNI is the class loader associated with the method at the top of > the stack. Until something causes the app's class loader to touch > ByteBuffer, and thereby get added as an initiating class loader, the > test will fail. > > You can work around the problem by using ByteBuffer once in your app > before calling into the JNI code; that will ensure it's loaded. For > example, do this during initialization: > > ByteBuffer dummy = ByteBuffer.allocate(0); dummy = null; > > Also: please post any further questions about JNI development on the > android-ndk mailing list.
-- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

