android - AndroidRuntime::getJNIEnv() returns NULL -


i have below code snippet in jni part:

jnienv* env = androidruntime::getjnienv(); 

the above statement returns null in function. use env , call method in java code using callback mechanism.

it's part of code in getjnienv() returns null.

if (vm->getenv((void**) &env, jni_version_1_4) != jni_ok) {         return null; } 

can please tell me what's wrong code? looks pretty normal me since other functions in jni have similar implementation.

first, don't use androidruntime::getjnienv(). that's not part of ndk api. should using jni getenv function instead.

second, getenv returns null if current thread not attached vm. (remember, jnienv thread-specific.) if created thread yourself, need use jni attachcurrentthread function attach it.

both of these require javavm pointer. there's 1 of these per process, can during jni_onload or setup call program (getjavavm function) when have jnienv passed in.

if haven't yet, read through jni tips page (which includes references comprehensive jni docs).


Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -