title: Android Java JNI and C Char array Can't recognize the value
body: <p>I tried to pass the char array from java to c. I have googled the way to implement it. But when I tried to access the value of the array, the value was not correct.</p>
  
  <p>In fact, I tried to give the array a character. Just Like <code>buffer[i]='z'</code>, and the result is correct in android.</p>
  
  <p>Btw, the value I wanted was the value sent by the rs232. The value from the rs232 was ok.</p>
  
  <p>Someone told me to use the bytearray. Would it work? I was afraid of that the value from rs232 could not be store into the bytearray....</p>
  
  <p><code>Java</code></p>
  
  <pre><code>public native int OpenPort(int portnum,int brates);
  public native int ClosePort(int portnum);
  public native int READ(char[] databuffer);
  
  public char[] buffer=new char[40];
  
  int i;
  
  for(i=0;i&lt;40;i++)
      buffer[i]='s';  //initialization
  
  OpenPort(16,9600); // A function to open the rs232 port
  
  while (i&lt;1000)
  {
      READ(buffer);
      i++;
  }
  </code></pre>
  
  <p><code>JNI.c</code></p>
  
  <pre><code>JNIEXPORT jint JNICALL Java_com_example_ndk_Vehicles_READ(JNIEnv *env, jclass
  cls,jcharArray databuffer)
  {
  
      char tmp[40];
      jchar *buffer=(*env)-&gt;GetCharArrayElements(env,databuffer,0);
      memset(tmp,0,sizeof(tmp));
      PollComport(16,tmp,40); //will the problem here ? This function need a unsigned char[]
                              //,but in the c program I wrote , char[] was ok for this.
      memcpy(buffer,tmp,40);
  
      (*env)-&gt;ReleaseCharArrayElements(env, databuffer, buffer, 0);
  
      return 0;
  }
  </code></pre>