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

匿名 (未验证) 提交于 2019-12-03 00:56:02

问题:

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 Android v2.3 I don't get this error.

This error occurs at the point where I call AsyncTask class, where I pass a string array as argument

Could Anyone Help me??

回答1:

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)



回答2:

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.



回答3:

JNI Local Reference Changes in ICS



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!