I've finaly understand the solution given on stackoverflow by doing something like this :
JNIEnv *env;
jclass myClass;
jclass myInstance;
JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved)
{
(*vm)->AttachCurrentThread(vm, (void*)&env, NULL);
myClass = (*env)->FindClass(env, "com/main/MyClass");
myInstance = (*env)->FindClass(env, "com/main/MyInstance");
return JNI_VERSION_1_6;
}
One other note about JNI_OnLoad: any FindClass calls you make from there will happen in the context of the class loader that was used to load the shared library. Normally FindClass uses the loader associated with the method at the top of the interpreted stack, or if there isn't one (because the thread was just attached) it uses the "system" class loader. This makes JNI_OnLoad a convenient place to look up and cache class object references.
If you call FindClass from this thread, the JavaVM will start in the "system" class loader instead of the one associated with your application, so attempts to find app-specific classes will fail.
There are a few ways to work around this:- Do your
FindClass lookups once, in JNI_OnLoad, and cache the class references for later use. Any FindClass calls made as part of executing JNI_OnLoad will use the class loader associated with the function that calledSystem.loadLibrary (this is a special rule, provided to make library initialization more convenient). If your app code is loading the library, FindClass will use the correct class loader.
That's why I use FindClass on JNI_OnLoad() method.
But now, my application crash after the second call of CallObjectMethod ??
On the first call everything is correct, but on the second, the application crash, the difference between the two calls are the methodName, so I check the result of GetMethodID but no error ...
What am I missing ??