title: Receiving GetStringUTFChars with JNI
body: <p>I am learning to use JNI with <a href="http://www.worldcolleges.info/sites/default/files/jni.pdf" rel="nofollow">this</a> book. I am using it to communicate Java with C++.
  If you look a the page 25 of this book you can see a piece of C code that "translated to" C++ should look like this:</p>
  
  <pre><code>#include &lt;jni.h&gt;
  #include &lt;iostream&gt;
  #include "Prompt.h"
  
  using namespace std;
  
  JNIEXPORT jstring JNICALL
  Java_Prompt_getLine (JNIEnv *env, jobject obj, jstring prompt){
      char buf[128];
      const jbyte *str; 
      str = env-&gt;GetStringUTFChars(prompt, NULL);
      if(str == NULL){
          return NULL; /* OutOfMemoryError already thrown */
      }
      printf("%s", str);
      env-&gt;ReleaseStringUTFChars(prompt, str);
      /* We assume here that the user does not type more than
       * 127 characters */
      scanf("%s",buf);
      return env-&gt;NewStringUTF(buf);
  }
  </code></pre>
  
  <p>In my opinion, the declaration of str should be like this:</p>
  
  <pre><code>const char* str;
  </code></pre>
  
  <p>I just would like to understand if the book is wrong or there's some explanation for it. Because they do simmilar things later. My code works if I declare str as a char pointer but I would like to understand if I am doing something wrong.</p>
  
  <p>Thanks a lot and sorry if I posted something wrong. It's my first message on this community.</p>
  
  <p>EDIT:
  If I compile with jbyte* the compiler gives the following error:</p>
  
  <pre><code>openjdk-amd64/include" -I"/usr/lib/jvm/java-7-openjdk-amd64/include/linux" -shared -o libPrompt.so Prompt.cpp -fPIC
  Prompt.cpp: In function '_jstring* Java_Prompt_getLine(JNIEnv*, jobject, jstring)':
  Prompt.cpp:12:43: error: invalid conversion from 'const char*' to 'const jbyte* {aka const signed char*}' [-fpermissive]
  Prompt.cpp:17:40: error: invalid conversion from 'const jbyte* {aka const signed char*}' to 'const char*' [-fpermissive]
  In file included from Prompt.cpp:1:0:
  /usr/lib/jvm/java-7-openjdk-amd64/include/jni.h:1619:10: error:   initializing argument 2 of 'void JNIEnv_::ReleaseStringUTFChars(jstring, const char*)' [-fpermissive]
  </code></pre>