我认为问题就是这么说的。我使用的是Android NDK。我不能包括std,请不要使用矢量,只需简单易懂的c ++。 这就是我到目前为止所拥有的:
// filePaths = jobjectarray = Java String[] int elementCount = env->GetArrayLength(filePaths); // this should end up being the char[] with the filePaths in it char *cppFilePaths[elementCount]; for (int i = 0; i < elementCount; i++) { jstring jFilePath = (jstring) (env->GetObjectArrayElement(filePaths, i)); const char *cppFilePath = env->GetStringUTFChars(jFilePath, 0); // this does not work! cppFilePaths[i] = cppFilePath; env->ReleaseStringUTFChars(jFilePath, cppFilePath); env->DeleteLocalRef(jFilePath); }
使用此代码,我最终将cppFilePaths
包含elementCount
中最后一个字符串的filePaths
个条目。
我搜索了很多,发现了strcpy
或memcpy
,但到目前为止没有任何效果。
答案 0 :(得分:0)
现在可以使用了。我不知道,如果可以直接使用GetStringUTFChars
的结果,但直到现在没有错误......
const char *cppFilePaths[elementCount] = {}; for (int i = 0; i < elementCount; i++) { jstring jFilePath = (jstring) (env->GetObjectArrayElement(filePaths, i)); cppFilePaths[i] = env->GetStringUTFChars(jFilePath, 0); env->DeleteLocalRef(jFilePath); }