tags:

views:

24

answers:

1

Basically, I've been doing the following to retrieve Java Instance Fields (in this case, an int) and setting it to a new value like the following:

jclass cls = env->GetObjectClass(obj);
jfieldID fid = env->GetFieldID(cls, "myVariable", "I");
env->SetIntField(obj, fid, (jint)2012);

However, I'd like to do this for an individual int element in a java int array such that:

jclass cls = env->GetObjectClass(obj);
jfieldID fid = env->GetFieldID(cls, "myVariableArray", "[I");
PSUDOCODE: <"SET myVariableArray[0] = 2013" ... Is there a method for this?>

Is there such a thing?

+1  A: 

I found the answer after looking through 15+ documents.

// Grab Fields
jclass cls = env->GetObjectClass(obj);
jfieldID fid = env->GetFieldID(cls, "testField", "[I");

jintArray jary;
jary = (jintArray)env->GetObjectField(obj, fid);
jint *body = env->GetIntArrayElements(jary, 0);
body[0] = 3000;
env->ReleaseIntArrayElements(jary, body, 0);

ReleaseIntArrayElements is key ... it returns a copy back to the java Instance Variable.

Carlo del Mundo
AND it releases the memory allocated by GetIntArrayElements().
EJP