i have an object that is used for calling callback functions ----- static jobject o;
i have assigned the callback function to that object through a pointer, env -----
o=env->NewGlobalRef(callback);
The same pointer, env, points towards the function CallVoidMethod( ) that uses JNI to reach to the java code.
env->CallVoidMethod(o, methodId, pDeviceId, deviceStatus, statusReason, connectionProgressInfo);
However on calling this function, the system is getting crashed, and VM says that it's an invalid reference to static jobject o and then it crashes.
My code is as follows :
static jint android_net_wimax_subscribeDeviceStatusChange(JNIE nv* env, jobject clazz, jobject jdeviceId, jobject callback) {
// LOGD(" android_net_wimax_subscribeDeviceStatusChange() ->D1"); o = env->NewGlobalRef(callback); //o = callback;
// LOGD(" android_net_wimax_subscribeDeviceStatusChange() ->D2");
return (jint)::SubscribeDeviceStatusChange(deviceId, fun_IndDeviceStatusUpdate); }
void fun_IndDeviceStatusUpdate(WIMAX_API_DEVICE_ID_P pDeviceId, WIMAX_API_DEVICE_STATUS deviceStatus, WIMAX_API_STATUS_REASON statusReason, WIMAX_API_CONNECTION_PROGRESS_INFO connectionProgressInfo) {
JNIEnv *env = NULL; int nResult = -1;
// LOGD(" AttachCurrentThread() ->D1");
nResult = g_jVM->AttachCurrentThread(&env, NULL);
// LOGD(" AttachCurrentThread() ->D2-%d",nResult);
if ((nResult != 0) || (env == NULL)) { LOGD(" AttachCurrentThread() failed"); } else { // LOGD(" AttachCurrentThread() ->D3");
if(o == NULL) {
LOGD(" o is NULL ");
} else { LOGD(" o is not NULL ");
}
jclass cls = env->GetObjectClass(o);
// LOGD(" AttachCurrentThread() ->D4"); jmethodID methodId = env->GetMethodID(cls, "callback", "(Landroid/net/wimax/structs/DeviceId;III)V");
// LOGD(" AttachCurrentThread() failed->D5"); if (methodId) { env->CallVoidMethod(o, methodId, pDeviceId, deviceStatus, statusReason, connectionProgressInfo); }
if (g_jVM->DetachCurrentThread() != JNI_OK) { LOGE("%s: DetachCurrentThread() failed", FUNCTION); } }
// LOGD("JNI->CALLBACK->D3");
}
<<< D/wimax ( 1673): before CallVoidMethod() W/dalvikvm( 1673): JNI WARNING: 0x48e31dec is not a valid JNI reference W/dalvikvm( 1673): in Ldalvik/system/NativeStart;.run ()V (CallVoidMethodV) I/dalvikvm( 1673): "Thread-55" prio=5 tid=45 RUNNABLE I/dalvikvm( 1673): | group="main" sCount=0 dsCount=0 s=N obj=0x43b6c930 self=0x306370 I/dalvikvm( 1673): | sysTid=2000 nice=0 sched=0/0 cgrp=unknown handle=3194272
Kindly help me out