Issue
I want to find the numbers of row and column in the 2D objectArray of JNI. how i can do? please anybody can help me for this problem.
Solution
If you have array of array, you have to go via array of objects.
1d arrays from java are 1d arrays of primitives in JNI 2d arrays are arrays of objects
So, for code like this:
public class PassArray {
public static native void passBooleanArray(boolean [][] array);
public static void main(String[] args) {
boolean [][] boolArray = { { true, true, true }, {false, false, false} };
passBooleanArray(boolArray);
}
}
you need something like this:
/* get size of the array */
jsize len = (*env)->GetArrayLength(env, array);
for(int i=0; i<len; i++) {
/* get the array at following indexes of array; it will be referecende by C pointer */
jbooleanArray body = (*env)->GetObjectArrayElement(env, array, i);
jsize innerLen = (*env)->GetArrayLength(env, body);
jboolean *booleanBody = (*env)->GetBooleanArrayElements(env, body, 0);
for(int j=0; j<innerLen; j++) {
/* do some stuff */
printf("Boolean value: %s\n", booleanBody[j] == JNI_TRUE ? "true" : "false");
}
/* release body when you decide it is no longer needed */
(*env)->ReleaseBooleanArrayElements(env, array, booleanBody, 0);
}
Update:
take a look here:
https://github.com/mkowsiak/jnicookbook/tree/master/recipes/recipeNo026
for a working sample code.
Answered By - Oo.oO
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.