Android Jni Detected Error In Application: Jni Getmethodid Called With Pending Exception
Solution 1:
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.
Solution 2:
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
publicOverlayLine(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;'.
Solution 3:
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
Solution 4:
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
Solution 5:
Faced the similar problem when calling GetMethodID:
JNI DETECTED ERRORIN APPLICATION: thread Thread[1,tid=15092,Runnable,Thread*=0x791c1b8000,peer=0x7278ab58,"main"] using JNI after critical get
... incallto 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);
Post a Comment for "Android Jni Detected Error In Application: Jni Getmethodid Called With Pending Exception"