I have native code with pthread and when Im calling pthread_create I’m passing the JNIEnv * that I got from the JAVA code as an argument to the thread function.
The JNIEnv * is valid and all the calls using are succefull beside the call
(jclass)i_env->NewGlobalRef(i_env->FindClass(“my/package/com/Myclass”));
which returns null.
Why is that?
10xs,
Nahum
JNIEnv is thread specific. You can not use one JNIEnv from one thread in another.
To get JNIEnv for current thread you must call AttachCurrentThread of JavaVM object. Read it here: http://developer.android.com/guide/practices/design/jni.html#JavaVM_and_JNIEnv
And to get JavaVM object use JNI_OnLoad function: http://developer.android.com/guide/practices/design/jni.html#native_libraries