title: Android JNI Callback to java from C++
body: <p>I tried to create a callback from jni to java, But when ever execute my code from cpp thread, findClass method return null, But the same class path &amp; method properly executing from jni thread(Native Thread). </p>
  
  <pre><code>static JavaVM * s_Jvm;
  
  
  JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved)
  {
  s_Jvm = vm;
  return JNI_VERSION_1_4;
  }
  
  
  void callbackToJava() {
  JNIEnv *env;
  
  res = s_Jvm-&gt;GetEnv((void**) &amp;env, JNI_VERSION_1_4);
          LOGI("status:%d",res);
          if(res &lt; 0) {
                  LOGI("callback_handler: failed to get JNI environment, "
                       "assuming native thread");
                  res = s_Jvm-&gt;AttachCurrentThreadAsDaemon(&amp;env, NULL);
                  LOGI("res:%d",res);
                  if(res == JNI_OK) {
                      LOGI("JNI_ok");
                  }
                  if(res &lt; 0) {
                      LOGI("callback_handler: failed to attach "
                           "current thread");
                      return;
                  }
              }
  
  if (res &lt; 0) {
           LOGI("Can't create Java VM\n");
           return;
       }
       cls = (env)-&gt;FindClass("com/test/controller/NativeTest");
       if (cls == NULL) {
           LOGI("Class is null"); //**Error Line**
           goto destroy;
       }
  
       mid = (env)-&gt;GetStaticMethodID(cls, "display",
                                       "()V");
       if (mid == NULL) {
           LOGI("Mid is null");
           goto destroy;
       }
  
  (env)-&gt;CallStaticVoidMethod(cls, mid, "()V");
  
   destroy:
       if ((env)-&gt;ExceptionOccurred()) {
           (env)-&gt;ExceptionDescribe();
       }
       (jvm)-&gt;DestroyJavaVM();
  </code></pre>
  
  <p>}</p>