error reason
Most of the job objects created by jnienv are local variables, which can no longer be used after they are out of function scope
So be sure to turn these variables into global variables, pass them to external pointers or references, and release them when they are used up
correct code
//char Arrays to jstring
void toString(const char *charArray, jstring &string) {
JNIEnv *env = nullptr;
bool detached = JNI::jvm->GetEnv((void **) &env, JNI_VERSION_1_6) == JNI_EDETACHED;
if (detached) JNI::jvm->AttachCurrentThread(&env, nullptr);
jstring localString = env->NewStringUTF(charArray);
string = (jstring) env->NewGlobalRef(localString);
if (detached) JNI::jvm->DetachCurrentThread();
}
//Calling Methods
jstring string = nullptr;
toString(charArray, string);
//use
env->CallVoidMethod(interface, onErrorMethod, code, string);
//release
env->DeleteGlobalRef(string);
string = nullptr;
Read More:
- [Solved] JNI DETECTED ERROR IN APPLICATION: GetStringUTFChars received NULL jstring
- QT solves error: use of deleted function and is private within this context
- C++ Use of deleted function error
- Go declares that the local variable does not use command line arguments. Main. Go: 4:6: a declared but not used
- flask init-db Error: Error: Could not locate a Flask application. Use the ‘flask –app’ option, ‘FLASK_APP’ environment variable, or a ‘wsgi.py’ or ‘app.py’ file in the current directory.
- Spring-boot Use dubbo Error: ERROR 8404 o.s.boot.SpringApplication:Application run failed
- The SDK of Android webrtc compiled with Ninja – C out / release command reported an error, and the Android NDK processing method could not be found
- Report Duplicate keys detected: ‘0’. This may cause an update error in VUE and the solution
- [Solved] Gradle NullPointerException at com.android.build.gradle.internal.ndk.NdkHandler.getPlatformVersion
- [Solved] JNI Error: Fatal signal 11 (SIGSEGV)
- Spark-shell startup error: Yarn application has already ended! It might have been killed or unable to launch application master
- [Solved] Cannot synthesize weak property in file using manual reference counting
- ERROR: JDWP Unable to get JNI 1.2 environment, jvm
- [Solved] Mavenwas cached in the local repository
- [Solved] Error ‘false‘ undeclared (first use in this function)
- Error lnk2038: detected “_ ITERATOR_ DEBUG_ Mismatched ‘level’ value of ‘0’
- [Solved] error LNK2038: Detected mismatch of “RuntimeLibrary”: The value “MDd_DynamicDebug” does not match the value “MTd_StaticDebug”
- [Solved] Compile Error: undefined reference to `google::FlagRegisterer::FlagRegisterer
- [Solved] paddle:FatalError: `Segmentation fault` is detected by the operating system.
- Error: a JNI error has occurred, please check your installation and try again