java - Program crashes when I call CallVoidMethodA -
i try call several non-static java methods c. i've checked if of object, method or env variables null, none of them are. program works when use static methods instead of non-static
javavm *jvm; jobject g_obj; jmethodid g_mid; void func(){ jclass dtk_anpr_test; jmethodid dtk_anpr; dtk_anpr_test = (*env)->findclass(env, "dtkanprtest"); g_mid = (*env)->getmethodid(env, dtk_anpr_test, "anpr", "(i)v"); jobject obj = (*env)->newobjecta(env, dtk_anpr_test, g_mid, val); g_obj = (*env)->newglobalref(env, dtk_anpr_test); }
and call (*env)->callvoidmethoda(env, g_obj, g_mid, val);
same method or method, program crashes @ point. problem object or else ?
p.s. use attachcurrentthread
, detachcurrentthread
call method time native code
p.s. there similar thread, didn't solve problem: jni crashes when calling callvoidmethod
to return constructor function of class getmethodid
, pass <init>
method name, not class name. the docs:
jobject newobjecta(jnienv *env, jclass clazz, jmethodid methodid, const jvalue *args);
constructs new java object. method id indicates constructor method invoke. id must obtained calling getmethodid()
<init>
method name , void (v) return type.
so change code to:
g_mid = (*env)->getmethodid(env, dtk_anpr_test, "<init>", "(i)v");
also, aren't saving reference object creating newobjecta
. change code this:
g_obj = (*env)->newglobalref(env, obj);
the reason code working static methods class object used rather object instance when calling static method.
Comments
Post a Comment