我正在调用 JNI_OnLoad 来保存 JavaVM* localy:
JavaVM * and_jvm = NULL;
jint JNI_OnLoad(JavaVM* vm, void* reserved)
{
and_jvm = vm;
return JNI_VERSION_1_6;
}
当我开始我的线程时,我打电话
void * thread_f (void * v)
{
jint attachResult = and_jvm->AttachCurrentThread(&env,NULL);
//The attachResult is 0.
jclass my_class= (jclass)env->NewGlobalRef(env->FindClass("my/package/com/MyClass"));
//my_class is 0
if (my_class == 0)
return NULL;
}
如果我从线程中调用 NewGlobalRef,它会返回一个有效的对象。怎么了?
10xs,那鸿