title: JNI converting native unsigned char arry to jbyte array
body: <p>Í have JNI function that needs to return a jbyte array. The array contains byte data of a c  struct with data. But i get an error when i pass the data form the unsinged char array to the jbyte array.</p>
  <p>The C struct is defined as followed:</p>
  <pre><code>// ObjectInfo struct definition
   struct ObjectInfo {
      int ObjectXCor;
      int ObjectYCor;
      int ObjectMass;
   };
  
   // ObjectInfo struct definition
   struct SensorDataStruct{
      int PingData;
      int IRData;
      int ForceData;
      int CompassData;
   };
  
   // ObjectInfo struct definition
   union PackedSend{
      struct CommStruct{
          ObjectInfo VisionData;
          SensorDataStruct SensorData;
      } CommData;
      unsigned char bytes[28];
   }SendData;
  </code></pre>
  <p>The JNI method is defined as followed:</p>
  <pre><code>JNIEXPORT jbyteArray JNICALL Java_com_example_communicationmodule_MainActivity_Convert(
      JNIEnv *env, jobject,
      jint var1,
      jint var2,
      jint var3,
      jint var4,
      jint var5,
      jint var6,
      jint var7)
  {
  // Array to fill with data
  jbyteArray Array;
  
  // Init  java byte array
  Array = env-&gt;NewByteArray(28);
  
  SendData.CommData.SensorData.PingData = var1;
  SendData.CommData.SensorData.IRData = var2;
  SendData.CommData.SensorData.ForceData = var3;
  SendData.CommData.SensorData.CompassData = var4;
  SendData.CommData.VisionData.ObjectXCor = var5;
  SendData.CommData.VisionData.ObjectYCor = var6;
  SendData.CommData.VisionData.ObjectMass = var7;
  
  //Put the native unsigned chars in the java byte array
  for(int Index=0; Index &lt; 28; Index++){
      Array[Index] = SendData.bytes[Index];
  
  }
  
  
  // Return java array
  return Array;
  }
  </code></pre>
  <p>The error that i get is:
  jni/HelperFunctions.cpp:44:38: error: no match for 'operator=' in '*(Array + ((unsigned int)Index)) = SendData.PackedSend::bytes[Index]'</p>
  <p>My question is wat is the proper way to convert the native unsigned char array to the a jbyte array? Doe anyboy have a suggestion? All tips are welcome!</p>
  <h1>Update</h1>
  <p>After casting to (jbyte) i get the the following errors:
  jni/HelperFunctions.cpp:54:46: error: no match for 'operator=' in '*(Array + ((unsigned int)Index)) = (jbyte)SendData.PackedSend::bytes[Index]'
  jni/HelperFunctions.cpp:54:46: note: candidate is:
  C:/android-ndk-r9/platforms/android-8/arch-arm/usr/include/jni.h:66:7: note: _jbyteArray&amp; _jbyteArray::operator=(const _jbyteArray&amp;)</p>
  <p>The casting code is as followed:</p>
  <pre><code>//Put the native unsigned chars in the java byte array
  for(int Index=0; Index &lt; 28; Index++){
      Array[Index] = (jbyte) SendData.bytes[Index];
  }
  </code></pre>
  <p>Does anybody have a idea or suggestion? Everthing is welcome!</p>