Using JNI I am storing a reference to a Java method object ( obj
) in order to call it later from C:
jobject obj = (*newEnv)->NewObject(newEnv, cls, mid);
where newEnv
is my environment, cls
is my class ID and mid
is my method ID.
Everything works fine except that upon creating this object to be used as a reference later, it actually calls the method right away.
I would like to just create the object for later and not call the method immediately.
Thanks to Gabe Sechan's comments I was able to figure it out:
jmethodID construct = (*newEnv)->GetMethodID(newEnv,cls,"<init>","()V");
jobject obj = (*newEnv)->NewObject(newEnv, cls, construct);
Then I can call the method I want using:
(*newEnv)->CallVoidMethod(newEnv, obj, mid);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.