1

当我尝试构建时,Eclipse 给了我这个错误:

jni/cyberlevel9.c:17:31: error: request for member 'NewDirectByteBuffer' in something  not a structure or union
jni/cyberlevel9.c:18:28: error: request for member 'NewGlobalRef' in something not a structure or union

这是代码的问题部分:

JNIEXPORT jobject JNICALL Java_com_cyberbg_natcamlevel9_NativeCameraLevel9Start_allocNativeBuffer(JNIEnv* env, jobject this, jlong size)
{
void* buffer = malloc(size);
jobject directBuffer = env->NewDirectByteBuffer(buffer, size);
jobject globalRef = env->NewGlobalRef(directBuffer);

return globalRef;
//return (NewDirectByteBuffer*)(*env)->NewDirectByteBuffer(buffer, size);
}
4

1 回答 1

7

来自 C 程序的 JNI 调用看起来像

(*env)->fun(env, p1, ...)

您的调用风格在 C++ 中是可以的,其中定义了一个特殊的包装类jni.h

env->fun(p1, ...)

您可以通过简单地重命名jni/cybrrlevel9.c来解决您的问题jni/cyberlevel9.cpp

或者,

jobject directBuffer = (*env)->NewDirectByteBuffer(env, buffer, size); 
jobject globalRef = (*env)->NewGlobalRef(env, directBuffer);
于 2013-07-04T19:45:24.747 回答