On Jan 9, 2:00 pm, "[email protected]" <[email protected]> wrote: > i am trying to make callbacks to my android application from a native > C thread using JNI. however when i call FindClass it returns a NULL > value. i need to get the jclass value returned by FindClass() to > call GetStaticMethoID to make calls back up to my android application.
How is androidCback() getting called? The class loader that FindClass uses is the same as the class loader associated with the current native method. If there's no Java-visible native method on the call stack, because you just attached the thread through JNI, it will use the "system" class loader, which has access to the Android classes but not to anything app-specific. (Android apps are loaded by a user-defined class loader, not the "system" / "application" / CLASSPATH class loader.) There is one exception to this rule: in JNI_OnLoad, we use the class loader associated with the shared lib itself, which is why it works there. You can see some similar anguish in the runtime startup -- frameworks/ base/core/jni/AndroidRuntime.cpp, AndroidRuntime::findClass(), has a related problem because the calling method comes out of the bootstrap class loader and thus the FindClass is very limited in scope. Your best bet here is probably to do the class lookup at JNI_OnLoad time, call NewGlobalRef to make it a global reference, and cache it locally. You could also cache a copy of the class loader for future lookups (see the findClass() mentioned above for an example of calling loadClass() on a ClassLoader object). See also FindClass in the JNI ref: http://java.sun.com/javase/6/docs/technotes/guides/jni/spec/functions.html#wp16027 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

