ReleaseStringUTFChars对于std :: string不起作用

编程入门 行业动态 更新时间:2024-10-12 12:32:43
本文介绍了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不起作用

本文发布于:2023-11-23 01:13:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1619575.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不起作用   ReleaseStringUTFChars   std   string

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!