如何处理来自native-lib.cpp类的更多字符串
我试过这个
爪哇:
....
public List<String> getFooAsList(){
return new ArrayList(this.getData());
}
private native String[] getData();
JNI
#include <jni.h>
JNIEXPORT jobjectArray JNICALL
como_foo_bar_getData
(JNIEnv *env, jobject jobj){
jobjectArray ret;
int i;
char *data[5]= {"Hello from C++", "Hello from B++", "Hello from A++", "Hello from D++";
ret= (jobjectArray)env->NewObjectArray(5,env->FindClass("java/lang/String"),env->NewStringUTF(""));
for(i=0;i<5;i++) env->SetObjectArrayElement(ret,i,env->NewStringUTF(data[i]));
return(ret);
}
nativ-liv.cpp
#include <jni.h>
#include <string>
extern "C"
JNIEXPORT jstring
JNICALL
Java_in_gov_civilsupplieskerala_myapplication_MainActivity_stringFromJNI(
JNIEnv *env,
jobject /* this */) {
std::string hello = "Hello from C++";
std::string hello3 = "Hello from A++";
std::string hello2 = "Hello from B++";
std::string hello1 = "Hello from D++";
return env->NewStringUTF(hello.c_str());
}
它只取第一个值,我如何从native-lib.cpp类中获取所有字符串值