Kavitha Madhu
Kavitha Madhu

Reputation: 27

jobject returned by JNI isn't setting fields

I use JNI to set some fields as follows:

JNIEXPORT void JNICALL Java_HelloJNI_sayHello(JNIEnv *env, jobject thisObj) {
jclass complexClass = (*env)->GetObjectClass(env, thisObj);
jfieldID fid = (*env)->GetFieldID(env, complexClass, "exampleVar", "I");
jint secondnumber = 30;
(*env)->SetIntField(env, complexClass, fid, secondnumber);
}

But after setting the int field, when I read it back where I made the first call from, the value isn't modified. I tried providing both setter as well as made the field "exampleVar" public but that doesn't seem to help.

Upvotes: 0

Views: 749

Answers (1)

user207421
user207421

Reputation: 310980

If it's a non-static field, you need to provide the object to SetIntField(), not the class.

Your lack of error checking has concealed this.

Upvotes: 2

Related Questions