Android JNI错误:使用boolean参数调用函数会导致崩溃

时间:2015-08-05 17:51:01

标签: java android c++ android-ndk java-native-interface

我试图调用此JAVA函数:

public String getPreferredLanguage(boolean withRegion)

使用JNI GetMethodID,但我总是遇到崩溃,我在JNI部分尝试了很多关于功能签名的变体,但似乎没有任何帮助。

JNI代码:

methodID getPreferredLanguageMethod = env->GetMethodID(languageServiceClass, "getPreferredLanguage", "(Ljava/lang/Boolean;Z)Ljava/lang/String;");
    if (!getPreferredLanguageMethod) {
        TTLOGD("LanguageService::getPreferredLanguage: ERROR getPreferredLanguageMethod is null\n");
    }

崩溃讯息:

JNI DETECTED ERROR IN APPLICATION: JNI CallObjectMethodV called with pending exception java.lang.NoSuchMethodError: no non-static method "Lcom/tabtale/mobile/acs/services/LanguageService;.getPreferredLanguage(Ljava/lang/Boolean;Z)Ljava/lang/String;"

知道我做错了吗?

1 个答案:

答案 0 :(得分:3)

在一遍又一遍地阅读this文档之后,我发现了我的问题,这就是JNI函数应该是这样的:

jmethodID getPreferredLanguageMethod = env->GetMethodID(languageServiceClass, "getPreferredLanguage", "(Z)Ljava/lang/String;");