Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
625 views
in Technique[技术] by (71.8m points)

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

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??

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...