In threads that I create directly (via pthread_create) calls to
FindClass are failing in some cases. After studying the docs and other
messages on this topic, I still can't spot any problems in my code.
To reduce complexity, I put a simple test call to FindClass right up
front in my thread proc. I find that FindClass calls on system classes
like java.lang.String will work on any thread, but if I refer to my
own application classes, then FindClass will only work on threads
created by the Java VM. Here's the relevant section of my thread proc.
Any suggestions?
Thanks
void *ThreadType::startProc(void *param)
{
JNIEnv *env;
jint rv = cachedJVM->AttachCurrentThread(&env, NULL); // cachedJVM
set in JNI_OnLoad
if (rv != 0) {
__android_log_print(ANDROID_LOG_DEBUG, "Trace", "Failed to attach
VM: AttachCurrentThread returns %d", rv);
return (void*) 1;
}
__android_log_print(ANDROID_LOG_DEBUG, "Trace",
"ThreadType::startProc - testing FindClass");
//jclass foo = jniEnv()->FindClass("java/lang/String"); // works!
jclass foo = jniEnv()->FindClass("<my app class path>"); //
fails!
if (foo == NULL) {
__android_log_print(ANDROID_LOG_DEBUG, "Trace",
"ThreadType::startProc - FindClass failed");
if (jniEnv()->ExceptionCheck())
jniEnv()->ExceptionDescribe();
return;
}
__android_log_print(ANDROID_LOG_DEBUG, "Trace",
"ThreadType::startProc - FindClass succeeded");
...
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to
andro...@googlegroups.com.
To unsubscribe from this group, send email to
android-ndk...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/android-ndk?hl=en.