Discussion:
JNI ERROR (app bug): attempt to use stale Local 0x31 (should be 0x39)
(too old to reply)
Алексей Кудинов
2018-11-25 17:50:34 UTC
Permalink
Good day. Wrote code that should set key values.

extern "C" JNIEXPORT jboolean JNICALL Java_com_example_woodman_testlibsettingsv2_frmMain_SetSystemKeysString(JNIEnv *env, jobject instance, jstring key_Name_) {
const char *key_Name = env->GetStringUTFChars(key_Name_, 0);

// TODO

jclass secClass = env->FindClass("android/provider/Settings$System");
jmethodID secMid = env->GetStaticMethodID(secClass, "putString", "(Landroid/content/ContentResolver;Landroid/net/Uri;Ljava/lang/String;Ljava/lang/String;)Z");

jclass activityThread = env->FindClass("android/app/ActivityThread");
jmethodID currentActivityThread = env->GetStaticMethodID(activityThread, "currentActivityThread", "()Landroid/app/ActivityThread;");
jobject at = env->CallStaticObjectMethod(activityThread, currentActivityThread);
jmethodID getApplication = env->GetMethodID(activityThread, "getApplication", "()Landroid/app/Application;");
jobject context = env->CallObjectMethod(at, getApplication);

jclass c_context = env->FindClass("android/content/Context");
jmethodID m_get_content_resolver = env->GetMethodID(c_context, "getContentResolver", "()Landroid/content/ContentResolver;");
jobject o_content_resolver;
o_content_resolver = env->CallObjectMethod(context, m_get_content_resolver);

jstring jStringParam = env->NewStringUTF(key_Name);
jboolean jStringKey = env->CallStaticBooleanMethod(secClass, secMid, o_content_resolver, jStringParam, env->NewStringUTF("1"));

env->DeleteLocalRef(jStringParam);

return jStringKey;}

But when I try to execute, I get an error.

E/stlibsettingsv: JNI ERROR (app bug): attempt to use stale Local 0x31 (should be 0x39)
A/stlibsettingsv: java_vm_ext.cc:542] JNI DETECTED ERROR IN APPLICATION: use of deleted local reference 0x31
java_vm_ext.cc:542] from boolean com.example.woodman.testlibsettingsv2.frmMain.SetSystemKeysString(java.lang.String)
java_vm_ext.cc:542] "main" prio=5 tid=1 Runnable
A/stlibsettingsv: java_vm_ext.cc:542] | group="main" sCount=0 dsCount=0 flags=0 obj=0x7968c450 self=0x74e3014c00
java_vm_ext.cc:542] | sysTid=32691 nice=-10 cgrp=default sched=0/0 handle=0x7568948548
java_vm_ext.cc:542] | state=R schedstat=( 316288736 11800419 156 ) utm=29 stm=2 core=5 HZ=100
java_vm_ext.cc:542] | stack=0x7fe34db000-0x7fe34dd000 stackSize=8MB
java_vm_ext.cc:542] | held mutexes= "mutator lock"(shared held)
java_vm_ext.cc:542] native: #00 pc 00000000003c26c0 /system/lib64/libart.so (art::DumpNativeStack(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, int, BacktraceMap*, char const*, art::ArtMethod*, void*, bool)+220)

Can everybody have a problem? I read a lot of forums and websites. There is
no solution anywhere. Thank.

Add: This line causes an error. jboolean jStringKey =
env->CallStaticBooleanMethod(secClass, secMid, o_content_resolver,
jStringParam, env->NewStringUTF("1")); CallStaticBooleanMethod. All the
rest work out correctly. The problem with calling the putString method.
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/a6719649-8679-486a-b0da-ed5a36b8b4a3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...