title: Call from Java to c++ and then from the same c++ method make a call to java method
body: <p>The following code can invoke a C++ method from Java.</p>
  
  <p><strong>JNITest.java</strong></p>
  
  <pre><code>public class JNITest  {
      static {
          System.load("D:\\gagan docs\\TestJava\\Example.dll");
      }
  
      public native int intMethod(int n);
  
      public static void main(String[] args) {
          JNITest jnitest = new JNITest();
          int square=jnitest.intMethod(5);
          System.out.println("HelloWorld");
          System.out.println("From init method"+square);
      }
  
  }
  </code></pre>
  
  <p><strong>Example.cpp</strong></p>
  
  <pre><code>#include "JNITest.h"
  #include&lt;string.h&gt;
  JNIEXPORT jint JNICALL Java_JNITest_intMethod(JNIEnv *env, jobject obj, jint num)
  {
      return num*num;
  }
  </code></pre>
  
  <p>But when I try to call a java method from the above CPP using the following, the JVM crashes.</p>
  
  <p>I have also tried with createJavaVM method to create JVM, but it crashed.</p>
  
  <p><strong>Example.cpp</strong></p>
  
  <pre><code>#include "JNITest.h"
  #include&lt;string.h&gt;
  static JavaVM *jvm = NULL
  JNIEXPORT jint JNICALL Java_JNITest_intMethod(JNIEnv *env, jobject obj, jint num) 
  {
      JNIEnv* jenv;
      int res = jvm-&gt;AttachCurrentThread((void **)&amp;jenv, NULL);
      return num*num;
  }
  </code></pre>
  
  <p>I am using Linux(64 bit)machine and JDK 64 bit(Java 1.6).</p>
  
  <p>I want to make a complete flow from Java -> C++ -> Java. Any information on this issue will be very useful.</p>