当前位置:   article > 正文

JNI DETECTED ERROR IN APPLICATION: can't call void com.example.wxy.ndks.Utils.fun3() on instance of_jni detected error in application:jni getfieldid

jni detected error in application:jni getfieldid
//cmake使用
JNIEXPORT void JNICALL
Java_com_example_wxy_ndks_Utils_funs2(JNIEnv *env, jobject instance, jstring methodName_,
                                      jstring methodSign_) {

    char *methodName = jstringToChar(env, methodName_);//方法名称
    char *methodSign = jstringToChar(env, methodSign_);//方法签名
    //获取字节码
    jclass clazz = env->GetObjectClass(instance);
    if (clazz == NULL) {
        return;
    }
    //获取 文件签名转换 jmethodid
    jmethodID motheid = env->GetMethodID(clazz, methodName, methodSign);
    if (motheid == NULL) {
        env->DeleteLocalRef(clazz);
        return;
    }
    //获取签名ID
    jstring data = env->NewStringUTF("hello!");
    if (data == NULL) {
        env->DeleteLocalRef(clazz);
        env->DeleteLocalRef(data);
        return;
    }

    //调用方法
     env->CallVoidMethod(instance, motheid, data)//出错原因
     //env->CallVoidMethod(clazz, motheid, data)
    //手动回收
    env->DeleteLocalRef(clazz);


}c

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/158513
推荐阅读
相关标签
  

闽ICP备14008679号