1
votes

I think the question says it all. I work with the Android NDK. I cannot include std, no use of vectors please, just plain and simple c++. Here's what I have so far:

// 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 &lt 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);
}

With this code I'll end up with cppFilePaths containing elementCount entries of the last String in filePaths.

I searched a lot and found out about strcpyor memcpy, but nothing worked so far.

1

1 Answers

0
votes

This works now. I have no idea, if it's okay to directly use the result of GetStringUTFChars, but until now no errors...

const char *cppFilePaths[elementCount] = {};

for (int i = 0; i &lt elementCount; i++) {
  jstring jFilePath = (jstring) (env->GetObjectArrayElement(filePaths, i));
  cppFilePaths[i] = env->GetStringUTFChars(jFilePath, 0);
  env->DeleteLocalRef(jFilePath);
}