title: How do I use SetArrayRegion to map an array from a C struct to Java class array?
body: <p>I want to access data members of a C struct(below) and map them onto an array in my java class. I have tried to used Set&lt;>ArrayRegion to map the values but I am going wrong somewhere. Below is an example of what I am trying to do. Can somebody please help me with the correct syntax to map the values?</p>
  
  <p><strong>c header</strong></p>
  
  <p>`</p>
  
  <pre><code>typedef struct a {
      long                            nls;
      uint8_t                         *lane; 
      long                            t; 
  
  } aa;
  
  typedef struct b {
      uint32_t                        id; 
      uint64_t                        timestamp_ms;
      long                            num_states;
      aa                      *move_states; 
  } bb;
  </code></pre>
  
  <hr>
  
  <p><strong>java class</strong></p>
  
  <pre><code>class J {
      int     i_id; 
      long        timestamp_ms; 
      long        num_states;
      long[]      nls;
      long[][]    lane;
      long[]      t;      
  
      }
  </code></pre>
  
  <hr>
  
  <p><strong>test.c</strong></p>
  
  <pre><code>JNIEXPORT jint JNICALL Java_com_android_...
    (JNIEnv *env, jclass c, jobject obj)
  {
  
  
      bb  c_struct;
  
      // do some operations on c_struct to populate the structure
  
      ....
  
  
      J   java_class;
      jFieldID fid;
      jclass cls = (*env)-&gt;GetObjectClass(env,obj);
  
  
      fid=(*env)-&gt;GetFieldID(env,cls,"i_id","I");
      (*env)-&gt;SetIntField(env,obj,fid,c_struct.id);
  
      ... similar for timestamp_ms,num_states
  
  
      // how do I map c_struct-&gt;move_states[i].nls to java_class.nls[i] ??
      // also how do I map c_struct-&gt;move_states[i].lane[j] to java_class.lane[i][j]?? 
  
  
  }`
  </code></pre>