title: Converting JNI Java byte[] to C++ bytearray, returning 0
body: <p>I've a really big problem here. I am trying to pass a byte[] from Java to C++ and I am getting negative values after the conversion. I have determined the problem from having unique characters in the Java byte[] which after converting and doing a log, the values are either 0 or negative. </p>
  
  <p>I have tried using a test byte[] of String characters and it works fine.</p>
  
  <p>Here is my code, if it helps.</p>
  
  <p>Java</p>
  
  <pre><code>public static native void SendMessage(byte[] message, int size); //size = message.length
  </code></pre>
  
  <p>C++</p>
  
  <pre><code>static void SendMessage(JNIEnv *env, jclass cls, jbyteArray array, jint array_length)
   {
       jbyte* content_array = (env)-&gt;GetByteArrayElements(array,NULL);
       //*env-&gt;GetByteArrayRegion(array,0,array_length,content_array); //tried this as well, same results
       LOGD("content:\n"); 
       for (int i=0; i &lt; array_length; i++) 
       {
           LOGD("%d",content_array[i]); 
       } 
  
       //EDIT
       SendMessage(client, (uint8_t*)content_array, array_length); //&lt;- could the problem be at the point where I convert it to uint8_t?
  
        (env)-&gt;ReleaseByteArrayElements(array,content_array,0); 
    }
  </code></pre>
  
  <p>Output</p>
  
  <pre><code>content: 48
  content: 23
  content: 13
  content: 56
  content: 0 // &lt;--- the problem starts here
  content: -122
  content: 0
  content: 78
  content: 32
  content: -28
  etc...
  ..
  ..
  </code></pre>
  
  <p>Now, using a simple test byte[]
  Java</p>
  
  <pre><code>String test = "ABC";
  byte[] message = test.getBytes();
  public static native void SendMessage(byte[] message, int size); //size = message.length 
  </code></pre>
  
  <p>C++</p>
  
  <pre><code>static void SendMessage(JNIEnv *env, jclass cls, jbyteArray array, jint array_length)
   {
       jbyte* content_array = (env)-&gt;GetByteArrayElements(array,NULL);
      //*env-&gt;GetByteArrayRegion(array,0,array_length,content_array); //tried this as well, same results
      LOGD("content:\n"); 
      for (int i=0; i &lt; array_length; i++) 
      {
          LOGD("%d",content_array[i]); 
        } 
        (env)-&gt;ReleaseByteArrayElements(array,content_array,0); 
    }
  </code></pre>
  
  <p>Output</p>
  
  <pre><code>content: 65 //this works perfectly
  content: 66
  content: 67
  </code></pre>
  
  <p>Thanks for your help. Much appreciated.</p>