JNI调用转换的jstring为char *JNI、jstring、char

2023-09-06 09:13:44 作者:⊙﹏⊙

我在我的cpp code中,我想转换为const char * JNI的功能。这是code我使用

I my cpp code contains a jni function that i wish to convert to const char*. This is the code i am using

extern "C" {
void Java_com_sek_test_JNITest_printSomething(JNIEnv * env, jclass cl, jstring str) {

    const char* mystring = env->GetStringUTFChars(env, str, 0);
    PingoScreen::notify();
}

我得到一个错误

no matching function for call to '_JNIEnv::GetStringUTFChars(JNIEnv*&, _jstring*&, int)

我究竟做错了什么?

What am i doing wrong ?

推荐答案

根据该文件,

GetStringUTFChars常量jbyte * GetStringUTFChars(JNIEnv的* ENV,字符串的jstring,jboolean * isCopy);

GetStringUTFChars const jbyte* GetStringUTFChars(JNIEnv *env, jstring string, jboolean *isCopy);

返回一个指针字节数组重新presenting在修订的UTF-8编码字符串。直到它被ReleaseStringUTFChars释放此数组是有效的()

Returns a pointer to an array of bytes representing the string in modified UTF-8 encoding. This array is valid until it is released by ReleaseStringUTFChars().

如果isCopy非空,那么* isCopy设置为JNI_TRUE,如果一份拷贝;或者它设置,如果没有副本作出JNI_FALSE。

If isCopy is not NULL, then *isCopy is set to JNI_TRUE if a copy is made; or it is set to JNI_FALSE if no copy is made.

所以最后一个参数应该是一个jboolean;

So the last parameter should be a jboolean;