From: EJP on
On 27/04/2010 3:02 PM, junyoung wrote:
> private native SetErrorHandle();

This isn't legal Java as there is no return type, but from this evidence
it's not static.

> sClass->ThrowNew(sEnv, "Error is here");

That's not the correct syntax, and it's also a terrible error message.
Surely the system you're interfacing to is providing some information of
its own?

> JNIEXPORT jint SetErrorHandle(JNIEnv *aEnv, jclass aClass)

If this method is non-static this is the wrong signature for it. Have
you changed that without re-running javah? Also it's defined as 'jint',
which means that the native method returns 'int', but that's not what
you posted above.

> setCallback(generateException, aEnv)

You can't do that. A JNIEnv* is only valid within the JNI function it is
supplied to. Specifically it is not valid across thread boundaries.

> in this code, there are critical problems.

Yep.

> 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.

.... whatever AVAILABLE means. The real reason is that the JNIEnv* value
you are arranging to supply to it is no longer valid - see above.

> so my idea is to create new JNIEnv variable dynamically in
> generateException function.

You can do that with AttachCurrentThread().