title: How convert unsigned char to jbyteArray
body: <p>How do I convert a unsigned char buffer to a jbyteArray? I need get a C++ buffer and returns to Java through JNI.</p>
  
  <p>This is my current code to do that.</p>
  
  <pre><code>JNIEXPORT jbyteArray JNICALL Java_com_rmsdk_wrapper_RMServices_getImageBuffer(JNIEnv *env, jobject thiso,
      jint w, jint h) {
      emh::PNGSurface * surface = services-&gt;getImageBuffer(w,h);
  jbyteArray * buffer = (jbyteArray*)malloc(sizeof(jbyteArray)*surface-&gt;getBufferSize());
      unsigned char * imgBuff = surface-&gt;getBuffer();
  
      for(int i = 0; i &lt; surface-&gt;getBufferSize();i++){
          buffer = imgBuff;
          buffer++;
          imgBuff++;
      }
      return *buffer;
  };
  </code></pre>
  
  <p>I got the following error when compiling.</p>
  
  <pre><code>Compile++ thumb  : rmsdk &lt;= RMSDK_Wrapper_JNI.cpp
  /home/marcos/dev/workspace/rmsdk.native.wraper/jni/RMSDK_Wrapper_JNI.cpp: In function '_jbyteArray* Java_com_rmsdk_wrapper_RMServices_getImageBuffer(JNIEnv*, _jobject*, jint, jint)':
  /home/marcos/dev/workspace/rmsdk.native.wraper/jni/RMSDK_Wrapper_JNI.cpp:37: error: cannot convert 'unsigned char*' to '_jbyteArray**' in assignment
  make: *** [/home/marcos/dev/workspace/rmsdk.native.wraper/obj/local/armeabi/objs/rmsdk/RMSDK_Wrapper_JNI.o] Error 1
  </code></pre>
  
  <p>Ty.</p>