Two consecutive errors:
JNI error (App bug): Accessed stale reference 0xd0100019 (index 6 in a table of size 1)
One, Jclass direct assignment causes the problem.
Reason: cannot refer directly to Jclass
Solution:
Static Jclass MyClass;
Jclass cls = Env->findclass ("Com/xxx/class");
MyClass = (jclass) env->newglobalref (CLS);
Second, in a C + + method, the direct reference is not to Jobject, through the static Jobject MyObject, to the object set jobject all kinds of anomalies occur. The call to the static method is used. If it turns out to be
Env->callvoidmethod (Myobj,posteventfromnativeid, result), non-static method, when needed Jobject (is the current object), the alternative is to use static methods, You just need to pass in the Jclass. Jclass can be obtained through the error one's outcome scheme, essentially acquiring Jmethodid
Env->callstaticvoidmethod (Myclass,posteventfromnativeid, result);
Three, JNI callback Java in a listener,c++ callback to a string in Jni, callback to Java.
Jclass myclass= Env->findclass ("com/example/hejunlin/native"); Jfieldid Mondatasourcepreparedlistenerfieldid = Env->getfieldid (MyClass, "Mondatasourcepreparedlistener", "Lcom/
Example/hejunlin/native$ondatasourcepreparedlistener; ");
Jobject Mondatasourcepreparedlistener = Env->getobjectfield (myobj, Mondatasourcepreparedlistenerfieldid);
if (Mondatasourcepreparedlistener = = nullptr) {log_info ("Fail to find Jobject");
Gjavavm->detachcurrentthread ();
Return } Jmethodid ondatasourceprepared = Env->getmethodid (Mylistenerclass, "ondatasourceprepared", "Ljava/lang/String;
) V ");
jstring result = Env->newstringutf (input_filename); Env->callvoidmethod (Mondatasourcepreparedlistener, ondatasourceprepared, result);