title: JNI- FindClass returns null
body: <p>I know it is a common problem, i searched google and look at everything in first 4 pages, have tried many possibilities but no result so far.</p>
  
  <p>Here is C++ code part:</p>
  
  <pre><code>JNIEnv* create_vm(JavaVM ** jvm) {
  
      char * str=(char *)"-Djava.class.path=.";
  
      JNIEnv *env;
  
      JavaVMInitArgs vm_args;
  
      JavaVMOption options;
  
      options.optionString = str; //Path to the java source code
  
      vm_args.version = JNI_VERSION_1_6; //JDK version. This indicates version 1.6
  
      vm_args.nOptions = 1;
  
      vm_args.options = &amp;options;
  
      vm_args.ignoreUnrecognized = 0;
  
  
  
      int ret = JNI_CreateJavaVM(jvm, (void**)&amp;env, &amp;vm_args);
  
      if(ret &lt; 0)
  
          printf("\nUnable to Launch JVM\n");     
  
      return env;
  
  }
  
  
  
  int main(int argc, char* argv[])
  
  {
  
      JNIEnv *env;
  
      JavaVM * jvm;
  
      env = create_vm(&amp;jvm);
  
      if (env == NULL)
  
          return 1;
  
  
  
  
      jclass clsMain=NULL;
      jmethodID mid = NULL;
  
      //Obtaining Classes
      clsMain = env-&gt;FindClass("Main");
  
      //Obtaining Method IDs
      if (clsMain != NULL)
      {
          mid       = env-&gt;GetStaticMethodID(clsMain, "myMethod", "(Ljava/lang/String;)Z");
      }
      else
      {
          printf("\nUnable to find the requested class\n");    //this runs    
      }
  </code></pre>
  
  <p>...</p>
  
  <p>I do not know how to catch exception and learn its name in JNI.</p>
  
  <p>Also Main.class is in the same directory with the file has this C++ code part.</p>
  
  <hr>
  
  <p><strong>Edit:</strong></p>
  
  <p>i add these lines to find exception from Java after FindClass line:</p>
  
  <pre><code>clsMain = env-&gt;FindClass("Main");
  
  jthrowable exc;
  exc = env-&gt;ExceptionOccurred();
       if (exc) {
           jclass newExcCls;
           env-&gt;ExceptionDescribe();
           env-&gt;ExceptionClear();
  
       }
  </code></pre>
  
  <p>then it throws NoClassDefFoundException</p>
  
  <p>thus i edit the JavaVMInitArgs.options</p>
  
  <p>i mean i edit the:</p>
  
  <pre><code>char * str=(char *)"-Djava.class.path=.";
  </code></pre>
  
  <p>line to:</p>
  
  <pre><code> char * str=(char *)"-Djava.class.path=/path/to/my/jars:/path/to/my/other/jars:."; 
  </code></pre>
  
  <p>now everything is fine.
  Thanks</p>