0

how can i handle more string from native-lib.cpp class

i tried this

Java:

....
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());

}

It only take first value,how can i take all string value from native-lib.cpp class

0 Answers0