Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JNI : Getting an Array of Arrays of Strings back to Java

Status
Not open for further replies.

Gaelle

Programmer
Jun 20, 2001
62
FR
Hi !

I am trying to get a C Array of Arrays of *(char) back to a Array of Arrays of String to Java, using JNIs.
I manage to bring back a Array of Strings, but Don't know how to make for a 2d array.
Has anyone any idea ?

Thanks,
Gaelle.

PS : here's a bit of my 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, &quot;java/lang/String&quot;), 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;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top