如何使用2个字符串参数从jni java库调用?

时间:2017-01-26 10:56:09

标签: android c++ parameters callback java-native-interface

我试过这样:

$source = "U:\TEST\Compression\images"
$destination = "U:\TEST\Compression\image_resizer"
$exclude_list = @("*Imprimerie","*Photos*")

$source_listephotos = Get-ChildItem $source -Exclude $exclude_list -Recurse

foreach ( $source_photos in $source_listephotos ) {
    Resize-Image -InputFile $source_photos.FullName -Scale 30 -OutputFile (Join-Path $destination $source_photos.Name) -Verbose
}

但我得到了回复:

 void CallbackStringFromJni(const char *name, const char *type)
 {
    jboolean isAttached;
    JNIEnv *env;
    jmethodID mid;
    jstring js, js2;
    LOGE("callbackStringFromJni Begin");
    env = getJniEnv(&isAttached);
    if (env == NULL)
            goto FAIL0;

    mid = getApplicationJniMethodId(env, applicationJniObj, "callbackStringFromJni", "(SS)V");
    if (mid == NULL)
            goto FAIL1;

    js = (*env)->NewStringUTF(env, name);
    js2 = (*env)->NewStringUTF(env, type);
    (*env)->CallVoidMethod(env, applicationJniObj, mid, js, js2);

    if (isAttached)
    {
        (*global_vm)->DetachCurrentThread(global_vm);
    }
    LOGE("callbackStringFromJni End");
    return;
FAIL1:
    if (isAttached)
    {
        (*global_vm)->DetachCurrentThread(global_vm);
    }
FAIL0:
    LOGE("callbackStringFromJni FAILED");
    return;
}

我在java中的方法如下:

01-26 11:53:02.500: E/VidyoMobile app/src/main/jni/ndkVidyoSample.c(31091): getApplicationJniMethodId - getApplicationJniMethodId: Failed to get callbackStringFromJni method
01-26 11:53:02.603: E/AndroidRuntime(31091): java.lang.NoSuchMethodError: no non-static method "Lcom/vidyo/vidyocore/VidyoCoreApplication;.callbackStringFromJni(SS)V"

1 个答案:

答案 0 :(得分:0)

必须是这样的:

mid = getApplicationJniMethodId(env, applicationJniObj, "callbackStringFromJni", "(Ljava/lang/String;Ljava/lang/String;)V");

不是

"(SS)V"