L
lionel pacoud
I have a pb.
i'd like to store the ref. of a Java object in my C file and re use
it later.
when I try to re use it I obtain a Exception_access_violation
I join th code of my C file. If someone could help me.
-----------------
#include "timerFunction.h"
#include "com_scalpel_JNI_BackgroundFunction.h"
/* private field */
static JNIEnv *timer_global_env = NULL;
static jobject timer_global_obj = NULL;
static jclass timer_global_class = NULL;
void initTimer(JNIEnv *env, jobject obj) {
timer_global_env = env;
timer_global_obj = obj;
/* get object concerned */
jclass localRef_class =
(*timer_global_env)->GetObjectClass(timer_global_env,
timer_global_obj);
if (localRef_class == 0)
printf("NATIVE : error, unable to have local ref\n");
/* get an absolute ref on the object, the local one is lost at the
end of the function call */
timer_global_class =
(*timer_global_env)->NewGlobalRef(timer_global_env, localRef_class);
if (timer_global_class == 0)
printf("NATIVE : error, unable to have global ref\n");
}
void setTimer(int ms, void(* callback)(void)) {
timerStop = callback;
// get the method
global_mid = (*timer_global_env)->GetMethodID(timer_global_env,
timer_global_class, "throwSetTimer", "()V");
if (global_mid == 0) {
printf("NATIVE : method not found\n");
return;
}
(*timer_global_env)->CallVoidMethod(timer_global_env,
timer_global_obj, global_mid);
return;
}
....
}
i'd like to store the ref. of a Java object in my C file and re use
it later.
when I try to re use it I obtain a Exception_access_violation
I join th code of my C file. If someone could help me.
-----------------
#include "timerFunction.h"
#include "com_scalpel_JNI_BackgroundFunction.h"
/* private field */
static JNIEnv *timer_global_env = NULL;
static jobject timer_global_obj = NULL;
static jclass timer_global_class = NULL;
void initTimer(JNIEnv *env, jobject obj) {
timer_global_env = env;
timer_global_obj = obj;
/* get object concerned */
jclass localRef_class =
(*timer_global_env)->GetObjectClass(timer_global_env,
timer_global_obj);
if (localRef_class == 0)
printf("NATIVE : error, unable to have local ref\n");
/* get an absolute ref on the object, the local one is lost at the
end of the function call */
timer_global_class =
(*timer_global_env)->NewGlobalRef(timer_global_env, localRef_class);
if (timer_global_class == 0)
printf("NATIVE : error, unable to have global ref\n");
}
void setTimer(int ms, void(* callback)(void)) {
timerStop = callback;
// get the method
global_mid = (*timer_global_env)->GetMethodID(timer_global_env,
timer_global_class, "throwSetTimer", "()V");
if (global_mid == 0) {
printf("NATIVE : method not found\n");
return;
}
(*timer_global_env)->CallVoidMethod(timer_global_env,
timer_global_obj, global_mid);
return;
}
....
}