Errol Green Errol Green - 10 months ago 122
Java Question

Android JNI DETECTED ERROR IN APPLICATION: JNI GetMethodID called with pending exception

I'm trying to run a Googles OCR Tesseract with my android project. I have already complied tesseract with android-ndk and am receiving this error after I try and run the android project.

My environment is as follows

  • Android 5.1.1

  • android-ndk-r10e for windows

  • android-sdk-r22

For reference, I'm building from an example that is listed here Example Link

Thanks in advance!

Here is a snippet of my logcat result:

I/DEBUG ( 182): Revision: '0'
I/DEBUG ( 182): ABI: 'arm'
I/DEBUG ( 182): pid: 20291, tid: 20337, name: JavaBridge >>> com.enterprisem
obility.OCR <<<
I/DEBUG ( 182): signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
I/DEBUG ( 182): Abort message: 'art/runtime/] JNI DETECTED ERR
OR IN APPLICATION: JNI GetMethodID called with pending exception 'java.lang.NoSu
chFieldError' thrown in void
I/DEBUG ( 182): r0 00000000 r1 00004f71 r2 00000006 r3 00000000
I/DEBUG ( 182): r4 a0701db8 r5 00000006 r6 0000000b r7 0000010c
I/DEBUG ( 182): r8 00000000 r9 b486f520 sl a1c0ac00 fp 00000001
I/DEBUG ( 182): ip 00004f71 sp a07006d8 lr b6e503c5 pc b6e72f6c cpsr
I/DEBUG ( 182):
I/DEBUG ( 182): backtrace:
I/DEBUG ( 182): #00 pc 00039f6c /system/lib/ (tgkill+12)
I/DEBUG ( 182): #01 pc 000173c1 /system/lib/ (pthread_kill+52)
I/DEBUG ( 182): #02 pc 00017fd3 /system/lib/ (raise+10)
I/DEBUG ( 182): #03 pc 00014795 /system/lib/ (__libc_android_abor
I/DEBUG ( 182): #04 pc 00012f44 /system/lib/ (abort+4)
I/DEBUG ( 182): #05 pc 00228cd7 /system/lib/ (art::Runtime::Abo
I/DEBUG ( 182): #06 pc 000a7371 /system/lib/ (art::LogMessage::
I/DEBUG ( 182): #07 pc 000b1b17 /system/lib/ (art::JniAbort(cha
r const*, char const*)+1118)
I/DEBUG ( 182): #08 pc 000b2055 /system/lib/ (art::JniAbortF(ch
ar const*, char const*, ...)+68)
I/DEBUG ( 182): #09 pc 000b530f /system/lib/ (art::ScopedCheck:
:ScopedCheck(_JNIEnv*, int, char const*)+1346)
I/DEBUG ( 182): #10 pc 000b7755 /system/lib/ (art::CheckJNI::Ge
tMethodID(_JNIEnv*, _jclass*, char const*, char const*)+36)
I/DEBUG ( 182): #11 pc 001332f7 /data/app/com.enterprisemobility.OCR-1/l
ib/arm/ (Java_com_googlecode_tesseract_android_TessBaseAPI_nativeClass
I/DEBUG ( 182): #12 pc 0000614d /data/dalvik-cache/arm/data@app@com.ente
W/ActivityManager( 536): Force finishing activity 1 com.enterprisemobility.OC
I/DEBUG ( 182):
I/DEBUG ( 182): Tombstone written to: /data/tombstones/tombstone_07

Answer Source

The Abort message is relatively clear: you call GetFieldID(cls, fieldName) for a field name that does not exist in the class you pass to this function, but you don't check for that error, and continue to call other JNI functions. Unfortunately, you cannot ignore such errors. You must call ExceptionClear() before calling GetMethodID() or most of the JNI functions.

You can use addr2line to find which specific call to getMethodID() crashed, and based on this, derive which call to GetFieldID(cls, fieldName) failed. But I would advise to add error checking to all your JNI calls, because tomorrow some other function may throw an exception.