title: How do I access return value of a Java method returning java.lang.String from C++ in JNI?
body: <p>I am trying to pass back a string from a Java method called from C++. I am not able to find out what JNI function should I call to access the method and be returned a jstring value. </p>
  
  <p>My code follows:</p>
  
  <p><strong>C++ part</strong></p>
  
  <pre><code>main() {
      jclass cls;
      jmethodID mid;
      jstring rv;
  
  /** ... omitted code ... */
  
      cls = env-&gt;FindClass("ClassifierWrapper");
      mid = env-&gt;GetMethodID(cls, "getString","()Ljava/lang/String");
  
      rv = env-&gt;CallStatic&lt;TYPE&gt;Method(cls, mid, 0);
      const char *strReturn = env-&gt;GetStringUTFChars(env, rv, 0);
  
      env-&gt;ReleaseStringUTFChars(rv, strReturn);
  }
  </code></pre>
  
  <p><strong>Java Code</strong></p>
  
  <pre><code>public class ClassifierWrapper {
      public String getString() { return "TEST";}
  }
  </code></pre>
  
  <p><strong>The Method Signature</strong> (from "javap -s Class")</p>
  
  <pre><code>public java.lang.String getString();
    Signature: ()Ljava/lang/String;
  </code></pre>