[英]How to define a return type for a JNI method with a custom Object class?
I have a method in JNI (C++) and I want to be able to return a custom Object type (not a primitive or a String etc...) I've written something down but I keep getting java.lang.UnsatisfiedLinkError error. 我在JNI(C ++)中有一个方法,我希望能够返回一个自定义的Object类型(不是一个原语或一个String等...)我写了一些东西,但我一直得到java.lang.UnsatisfiedLinkError错误。
Here are the details: 以下是详细信息:
The method: 方法:
static jobject Java_android_sdk_Core_ProcessFrame(JNIEnv *env, jobject myobj, jbyteArray frameData)
{
jclass clazz;
jmethodID cid;
jobject jCoreOut;
static const char* const strClassName = "android/sdk/Core/CoreOutput";
clazz = env->FindClass(strClassName);
if (clazz == NULL) {
LOGE("Can't find class CoreOutput");
}
cid = env->GetMethodID(clazz,"<init>", "()V");
jCoreOut = env->NewObject(clazz, cid);
// Free local references
env->DeleteLocalRef(clazz);
return jCoreOut;
}
I have the methods descriptors defined in the following way: 我有以下列方式定义的方法描述符:
static const JNINativeMethod gMethods[] = {
{ "CreateCore", "(III)V", (void*) Java_android_sdk_Core_CreateCore },
{ "ProcessFrame", "([B)Landroid/sdk/Core/CoreOutput;", (void*) Java_android_sdk_Core_ProcessFrame }
};
I'm performing the method registration by calling on: 我正在通过调用以下方式执行方法注册:
if (env->RegisterNatives(clazz, gMethods,
sizeof(gMethods) / sizeof(gMethods[0])) != JNI_OK)
{
LOGE("Failed registering JNI methods");
return result;
}
And the registration for my other native methods is successful. 我的其他原生方法的注册是成功的。 (I'm able to use them...) (我能用它们......)
When I try to invoke the ProcessFrame method I get the following output from Logcat: 当我尝试调用ProcessFrame方法时,我从Logcat获得以下输出:
11-23 16:10:10.139: ERROR/AndroidRuntime(4923): java.lang.UnsatisfiedLinkError: ProcessFrame
I'm sure it has something to do with me not defining the method correctly. 我确定这与我没有正确定义方法有关。 Can anyone shed some light on this? 任何人都可以对此有所了解吗?
Can anyone point me to a good tutorial which covers more than handling of primitive types in JNI? 任何人都可以指出一个很好的教程,其中涵盖的不仅仅是处理JNI中的原始类型吗?
Thank you, 谢谢,
Itamar 伊塔马尔
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.