首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

AndroidRuntime:getJNIEnv() returns NULL

2012-12-31 
AndroidRuntime::getJNIEnv() returns NULL5down voteFirst, dont use AndroidRuntime::getJNIEnv(). Tha

AndroidRuntime::getJNIEnv() returns NULL


5down vote

First, don't use AndroidRuntime::getJNIEnv(). That's not part of the NDK API. You should be using the JNI "GetEnv" function instead.

Second, GetEnv returns NULL if the current thread is not attached to the VM. (Remember, JNIEnv is thread-specific.) If you created the thread yourself, you will need to use the JNI AttachCurrentThread function to attach it.

Both of these require a JavaVM pointer. There's only one of these per process, so you can get it during JNI_OnLoad or a setup call from your program (GetJavaVM function) when you have a JNIEnv passed in.

If you haven't yet, read through the?JNI Tips?page (which includes references to some comprehensive JNI docs).


热点排行