JNI char [] (char array) 的方法描述符是什么?

 2023-01-21    324  

问题描述

我的java类代码spipt.i想使用jni contect off jni:

从我的c文件中访问getreg_chal()方法.

JNI char [] (char array) 的方法描述符是什么?

public char[] getReg_chal() {
        return reg_chal;
    }

我的c文件执行一些JNI操作:

mid = (*env)->GetMethodID(env, info, "getReg_chal()", "()I");

mid = (*env)->GetMethodID(env, info, "getReg_chal()", ***);

我想知道我的char []的方法描述符.写入”()i”给我伪造方法描述符错误,因为()i用于int.我会填写*.
请帮我.预先感谢.

推荐答案

方法签名将为” ()[C”.

您可以阅读有关详细信息的在这里在这里.

要使用方法ID调用该方法,您只需写

之类的东西

jobject obj = ... // This is the object you want to call the method on
jcharArray arr = (jcharArray) (*env)->CallObjectMethod(env, obj, mid);
int count = (*env)->GetArrayLength(env, arr);
jchar* chars = (*env)->GetCharArrayElements(env, arr, 0);
// Here, "chars" is a C pointer to an array of "count" characters. It's NOT
// going to be 0-terminated, so be careful! Here's where you would do your
// logging or whatever. One possible way to do this is by turning the `jchar`
// array into a proper 0-terminated character string:
char * message = malloc(count + 1);
memcpy(message, chars, count);
message[count] = 0;
LOGD("NDK:LC: [%s]", message);

// When you're done you must call this!
(*env)->ReleaseCharArrayElements(env, arr, chars, 0);

以上所述是小编给大家介绍的JNI char [] (char array) 的方法描述符是什么?,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对77isp云服务器技术网的支持!

原文链接:https://77isp.com/post/26215.html

=========================================

https://77isp.com/ 为 “云服务器技术网” 唯一官方服务平台,请勿相信其他任何渠道。