Java Native Interface Question
I need to pass an object to a native method. The object contains several int fields and a field that is an int array (contains 32 int).
I have no problem with the int fields of the object, but do not know how to access the int array field of the object in the C code. What approach should be used to get/set values in the int array field of the object passed to the native method?
For int fields in the object passed to the native function I do the following to set the value:
For a field that is an array of int, it seems that I can get the field ID as follows:
fid = (*env)->GetFieldID(env, cls, "intFieldName", "I");
(*env)->SetIntField(env, myObj, fid, newValue);
The "Get<Type>Field" and "Set<Type>Field" methods can be used for object, boolean, byte, char, short, int, long, float, double. Nothing specific here for array. Should I use the GetObjectField method, if so can the object field then be handled as an array? This is where I am missing something. I have experimented with using the SetIntArrayRegion method but this causes an exception - obviously missing a necessary step here. I am hoping someone here can provide guidance on what I am missing, what JNI functions I should be using, or refer me to the appropriate page of the specification or other document where it is explained.
fid = (*env)->GetFieldID(env, cls, "arrayFieldName", "[I");
Any suggestions are appreciated.