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 an
you should use ndk-stack tool in android NDK to find out the crashed position. see the link about ndk stack.
adb logcat > /tmp/foo.txt
$NDK/ndk-stack -sym $PROJECT_PATH/obj/local/armeabi -dump foo.txt
I have the same problem,and it confuse me 2 days.Finally the reason is that I pass the wrong object type.For example, the java code is
public OverlayLine(int mWidth,List<GeoPoint> mPoints);
and I register jni method as below:
gClass.mInitMethod = env->GetMethodID(gObject, "<init>", "(ILjava/lang/Object;)V");
and gets the error message as Errol encounter.And I fix the code
gClass.mInitMethod = env->GetMethodID(gObject, "<init>", "(ILjava/util/List;)V");
and the error gone.That you should pass the precise object type rather than 'Ljava/lang/Object;'.
Most likely the JNI mappings were incorrectly defined in your C++ code. JNI has very strict contracts about type mappings with Java. For example, before calling a Java object's method from JNI, we need its signature. So the method:
long myMethod (int n, String s, int[] arr);
is seen from JNI with the signature:
(ILJAVA/LANG/STRING;[I])J
You can read a very comprehensive overview of these rules here: http://www.rgagnon.com/javadetails/java-0286.html
Faced the similar problem when calling GetMethodID:
JNI DETECTED ERROR IN APPLICATION: thread Thread[1,tid=15092,Runnable,Thread*=0x791c1b8000,peer=0x7278ab58,"main"] using JNI after critical get
... in call to GetMethodID
A few calls before GetMethodID im use
inBufP = env->GetPrimitiveArrayCritical(jIn, NULL);
Solution : I can fix native crash by change GetPrimitiveArray to GetByteArrayElements
jboolean isCopy;
inBufP = env->GetByteArrayElements(jIn, &isCopy);
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.