Java JNI: How to set String [ ] field Of Java class from native method of C++ -
i have class : processsolution
public class processsolution { private string processid; private string processname; private string processsolutionsteps []; private string processremark; private string processnote; }
and want set 1 of field processsolutionsteps
native method ,
here step_name
nothing processsolutionsteps
jniexport jobjectarray jnicall java_nativeclass_jmain_getprocesssolutions (jnienv *env, jobject jobject) { clientlist *cl = new clientlist(); jmp_buf jmpb; int i, j , k; int listcount = 0, steps = 0; jobjectarray arrps = null; jobject clsobj; struct process *list = null; struct procdtl *pdtl; char *remark, *note, *step_name; list = (struct process *)calloc (sizeof(process) , 1); pdtl = (struct procdtl *)calloc (sizeof(procdtl) , 1); remark = (char*) calloc(201 ,1); note = (char*) calloc(201 ,1); step_name = (char*) calloc(201 ,1); cl->get_proc_list ( &listcount, &list ); jclass clsps = env->findclass("pojo/processsolution"); if( clsps == null ) return null; if( ( arrps = env->newobjectarray( listcount, clsps, null ) ) == null ); longjmp(jmpb,-1); ( = 0; < listcount; ++i ) { remark = get_proc_remark (list[i].proc_id); note = get_proc_note (list[i].proc_id); get_proc_list (list[i].proc_id , &steps, &pdtl); (j = 0; j < steps; j++) { memset(step_name, ' ', 200); strcpy(step_name, pdtl[j].desc[0]); if (data_in(ps.desc[1])) sprintf(step_name+strlen(step_name), "%s", pdtl[j].desc[1]); if (data_in(ps.desc[2])) sprintf(step_name+strlen(step_name), "%s", pdtl[j].desc[2]); if (data_in(ps.desc[3])) sprintf(step_name+strlen(step_name), "%s",pdtl[j].desc[3]); if (data_in(ps.desc[4])) sprintf(step_name+strlen(step_name), "%s", pdtl[j].desc[4]); } } }
my question how set processsolutionsteps []
above c++ method ?
thank you
jfieldid procsolstepsid = env->getfieldid(clsps, "processsolutionsteps", "[ljava/lang/string;"); jclass clsstr = env->findclass("java/lang/string"); (i = 0; < listcount; ++i) { jobject procsolobj = env->newobject(clsps, env->getmethodid(clsps, "<init>", "()v")); jobjectarray solsteps = env->newobjectarray(steps, clsstr, null); (j = 0; j < steps; ++j) { // prepare step_name env->setobjectarrayelement(solsteps, j, env->newstringutf(step_name)); } env->setobjectfield(procsolobj, procsolstepsid, solsteps); env->setobjectarrayelement(arrps, i, procsolobj); }
Comments
Post a Comment