JNI调用转换的jstring为char * [英] JNI call convert jstring to char*

查看:520
本文介绍了JNI调用转换的jstring为char *的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的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;

这篇关于JNI调用转换的jstring为char *的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆