ReleaseStringUTFChars对于std :: string不起作用 [英] ReleaseStringUTFChars not working for std::string

查看:71
本文介绍了ReleaseStringUTFChars对于std :: string不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在jni函数中使用了std :: string,但是我无法使用ReleaseStringUTFChars释放它.我得到的错误是:

I use std::string in my jni function, and I fail to release it using ReleaseStringUTFChars. The error I get is:

错误:没有匹配函数可调用NIEnv :: ReleaseStringUTF env-> ReleaseStringUTFChars(path,dir);

error: no matching function for call to NIEnv::ReleaseStringUTF env->ReleaseStringUTFChars(path, dir);

我知道,该函数希望获取字符串而不是字符串,但是我没有这样的变量.我该怎么办?

I understand, that instead of string, the function expects to get char, but I don't have such variable. What should I do?

这是我的jni函数:

void Java_com_example_android_OpenCVActivity_test (JNIEnv * env, jclass clazz, jstring path){

    std::string dir = env->GetStringUTFChars(path, 0);
   ....
env->ReleaseStringUTFChars(path, dir);
}

推荐答案

您需要传递与从 GetStringUTFChars()获得的值完全相同的值.并非如此.您正在传递 std :: string 给您的任何内容,这不一定是同一件事.

You need to pass it exactly the same value you got from GetStringUTFChars(). You're not. You're passing whatever std::string gives you, which isn't necessarily the same thing.

这篇关于ReleaseStringUTFChars对于std :: string不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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