tags:

views:

64

answers:

0

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");

}

I get the following error log

W/dalvikvm( 959): JNI WARNING: 0x491bde38 is not a valid JNI reference W/dalvikvm( 959): in Ldalvik/system/NativeStart;.run ()V (CallVoidMethodV) I/dalvikvm( 959): "Thread-55" prio=5 tid=45 RUNNABLE I/dalvikvm( 959): | group="main" sCount=0 dsCount=0 s=N obj=0x43b96780 self=0x3278d0 I/dalvikvm( 959): | sysTid=1320 nice=0 sched=0/0 cgrp=unknown handle=2917888 I/dalvikvm( 959): at dalvik.system.NativeStart.run(Native Method)

What changes should I make in the code to solve this problem ?