• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
  • Tim Holloway
  • Carey Brown
  • salvin francis

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;
You'll never get away with this you overconfident blob! The most you will ever get is this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!