title: Get object from an object with JNI in C
body: <pre><code>public class Student
  {
     private People people;
     private Result result;
     private int amount;
  }
  </code></pre>
  
  <p>Here is the sample of the class in Java; in C, I tried to get the "people" in "Student", but I failed. However, I am able to get int type "amount" from "Student".</p>
  
  <pre><code>jobject getObjectFromObject(JNIEnv *env, jobject obj, const char * fieldName)
  {
      jfieldID fid; /* store the field ID */
      jobject i;
  
      /* Get a reference to obj's class */
      jclass cls = (*env)-&gt;GetObjectClass(env, obj);
  
      /* Look for the instance field s in cls */
      fid = (*env)-&gt;GetFieldID(env, cls, fieldName, "L");
      if (fid == NULL)
      {
          return 0; /* failed to find the field */
      }
  
      /* Read the instance field s */
      i = (*env)-&gt;GetObjectField(env, obj, fid);
  
      return i;
  }
  </code></pre>
  
  <p>I am trying to pass "people" as a fieldName into the method, but it still gives the following error: "java.lang.NoSuchFieldError: people"</p>