JNI DETECTED ERROR IN APPLICATION: can't call void com.example.wxy.ndks.Utils.fun3() on instance of

//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

猜你喜欢

转载自blog.csdn.net/daimengs/article/details/81141259
今日推荐