Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JNI and an Array of Arrays of Strings

843829Mar 22 2010 — edited Mar 22 2010
Hi,

I'm getting an ArrayStoreException when trying to send an Array of Arrays of Strings from C to Java with JNI:

jtags[Array1, Array2, ...] (up to three arrays)
Array1[String1, String2, ...] (up to three strings)

Both the jtags array and the arrays inside have a maximum size of 3 elements.

I create an Array of Strings like this:
for(j = 0; j < szFound; j++) {
     (...)
     // Creates a Java string array
     arrayTemp = (*env)->NewObjectArray(env, sizeTmp, strCls, NULL);

     for (i = 0; i < sizeTmp; i++) {
          // Transforms a string into a Java string
          strTemp = (*env)->NewStringUTF(env, tagsTmp); 

// Adds Java string to a Java string array
(*env)->SetObjectArrayElement(env, arrayTemp, i, strTemp);
}
(...)
}
I them add these Arrays of Strings to jtags:
for(j = 0; j < szFound; j++) {
(...)
// Adds a Java string array to the final matrix
(*env)->SetObjectArrayElement(env, jtags, j, arrayTemp);
(...)
}
Hope this is the correct way of doing this.

In Java I read jtags like:
public String[][] tags() {
String tags[][] = nativeTagID();
return tags;
}
(...)
public native String[][] nativeTagID();
I've tried replacing String tags[][] = nativeTagID(); with String[][] tags = nativeTagID().clone();, with no success.

Any help would be great, don't know what else do to.

Edited by: Rorsch on Mar 22, 2010 1:26 PM

Edited by: Rorsch on Mar 22, 2010 2:22 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 19 2010
Added on Mar 22 2010
1 comment
354 views