[英]How to fill a C++ char[] with an JNI jobjectarray (Java String[])?
我認為這個問題說明了一切。 我使用Android NDK。 我不能包括std,請不要使用vector,而只能是簡單的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
其中包含filePaths
最后一個String的elementCount
條目。
我進行了很多搜索,發現了有關strcpy
或memcpy
,但到目前為止沒有任何效果。
現在可以使用。 我不知道是否可以直接使用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); }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.