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(deviceStatusChangeCB == NULL)
{
LOGD(" deviceStatusChangeCB is NULL ");
}
else
{
LOGD(" deviceStatusChangeCB is not NULL ");
}
jclass cls = env->GetObjectClass(deviceStatusChangeCB);
// 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");
}
Kindly help me out