call jni function dynamically without getting a JNIEnv handle as an
argument.
My application is using the jni interface to link java with c.
but, there is problem to use it. that is,
in side of the jni, I set a callback function to catch errors and
print it. this callback function tasks error informations.
and additionally, I can't expect the time this callback function wil
be called.
this is the simple structure of my code.
java:
ret = SetErrorHandle();
private native SetErrorHandle();
c:
static int generateException(void *aArg)
{
JNIEnv *sEnv = (JNIEnv *)aArg;
jclass sClass = (*aEnv)->FindClass("MyException");
sClass->ThrowNew(sEnv, "Error is here");
}
JNIEXPORT jint SetErrorHandle(JNIEnv *aEnv, jclass aClass)
{
/* this function will be called if there is an error */
/* first argument : function pointer
second argument : argument for function pointer
*/
setCallback(generateException, aEnv)
}
in this code, there are critical problems.
first one is sEnv variable pointer is not available in
generateException function.
whenever this function is called, it generated a segmentation fault
because the pointer is not AVAILABLE.
so my idea is to create new JNIEnv variable dynamically in
generateException function.
how do u think? if it is possible, how APIs I can reference?
thanks u.