Error: JNI ERROR (app bug): accessed stale global reference

后端 未结 4 1660
难免孤独
难免孤独 2020-12-16 14:39

I am getting this error JNI ERROR (app bug): accessed stale global reference When I run my app in Android OS v4, But when I run the same application in Andr

相关标签:
4条回答
  • 2020-12-16 14:45

    This error occurs when you call a method with an incorrect parameter type.

    Make sure your method signature matches exactly what you are passing. For a string array:

    jmethodID mid = env->GetMethodID(cls, methodName, "([Ljava/lang/String;)V");
    

    If you are creating it yourself, it would look something like this:

    jclass stringCls = env->FindClass("java/lang/String");
    jobjectArray mStringArray = env->NewObjectArray( mSize, stringCls, NULL);
    

    In your specific case, you are most likely not seeing the crash on Android 2.3 because you are calling AsyncTask.execute() which wasn't available until API 11 (Android 3.0) and your jmethodID is null. (It's a good idea to always check jclass and jmethodID for null after getting them)

    0 讨论(0)
  • 2020-12-16 14:49

    JNI Local Reference Changes in ICS

    0 讨论(0)
  • 2020-12-16 15:00

    This error occurs when you call a method with an incorrect parameter type.

    Addition, in this case you may be register the native method on Java code different from the native code. The difference can be you declare more or less parameters between the Java code and native code.

    0 讨论(0)
  • 2020-12-16 15:05

    This applies to kotlin:

    To add to what @krys has already mentioned, make sure that signatures on Kotlin side match exactly what you have in the JNI code. Even a simple Void (avoid explicit Void at the end of function signatures that return void on the JNI side) signature at the end of kotlin reference may fail and would make your debugging extremely frustrating.

    0 讨论(0)
提交回复
热议问题