I want to call a java method inside a pthread.
the C++ method start like this :
char* FileLoader::getStringFromFile(char* a_filename)
{
JNIEnv *env;
g_jvm->AttachCurrentThread (&env, NULL);
jclass cls = env->FindClass(JAVA_FILE_LOADER_CLASS);
...
g_jvm points to the JavaVM object. it is set when the app start in the JNI_OnLoad() method.
When “FindClass” is called, it throws a “noClassDefFoundError” but if I call this method in the main thread, it works as expected.
Have I forgotten something ?
Ok, I solve the problem with the advice of technomage :
In my JNI_OnLoad() method :
My first test has failed because I forgot to call NewGlobalRef().
This doc helped me to understand why it is needed.