Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

JNI : getting an array of arrays of strings back to java

Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone !
I am working with JNis in C and Java.
In my C program, I have as a result an Array of Arrays of *(char).
I would like to take it back to Java as an Array of Arrays of Strings.
I have managed to bring back an Array of Strings, but I don't know how to do with a 2D Array...
Can anyone tell me how to do or where to find the information ?

Here's a bit of my C code :
JNIEXPORT jobjectArray JNICALL Java_Test_getStrings0
(JNIEnv *env, jclass cls)
jstring str;
jobjectArray args=0;
jobjectArray ss=0;
jsize len=5;
jsize sslen =2;
char* sa[] = {"Hello", "world!", "JNI", "is", "fun!" };
char* tb[] = {"1","2","3","4","5"};
int i=0;

args=(*env)->NewObjectArray(env, len, jint, 0);
for (i=0;i<len;i++)
ss=(*env)->NewObjectArray(env, sslen, (*env)->FindClass(env, "java/lang/String"), 0);
str=(*env)->NewStringUTF(env, sa);
(*env)->SetObjectArrayElement(env, ss, 0, str);
str=(*env)->NewStringUTF(env, tb);
(*env)->SetObjectArrayElement(env, ss, 1, str);
(*env)->SetObjectArrayElement(env, args, i, ss);
return args;
I'm gonna teach you a lesson! Start by looking at this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic