title: JNI how to access Java Object (Integer)
body: <p>I have a JNI method to access java method which returns an Integer object. I do not want to return the primitive int type because this code will be modified to handle Generic objects. The following is what I have. I am not able to get the value of the Integer that I pass. The output at C++ side is something like </p>
  
  <pre><code>value = 0x4016f3d0
  </code></pre>
  
  <p>How can I get the actual value of Integer object that I pass at C++ end? </p>
  
  <p>Please help.</p>
  
  <p>Thanks,</p>
  
  <p>-H</p>
  
  <p><em>GenericPeer.cpp</em></p>
  
  <pre><code>JNIEXPORT void JNICALL Java_GenericPeer_print (JNIEnv *jenv, jclass jcls, jobject data){
   jclass peerCls = jenv-&gt;GetObjectClass(data);
   jmethodID mGetValue = jenv-&gt;GetMethodID(peerCls, "getValue","()Ljava/lang/Integer;");
   if(mGetValue == NULL){
     return (-1);
   } 
   jobject value = jenv-&gt;CallObjectMethod(data, mGetValue);
   cout&lt;&lt;"value = "&lt;&lt;value&lt;&lt;endl;
  
  }
  </code></pre>
  
  <p><em>GenericPeer.java</em></p>
  
  <pre><code>public class GenericPeer {
   public static native void print(Data d);
   static {
    System.load("/home/usr/workspace/GenericJni/src/libGenericJni.so");
   }
  }
  </code></pre>
  
  <p><em>Data.java</em></p>
  
  <pre><code>public class Data {
   private Integer value;
   pubilc Data(Integer v){ 
    this.value = v;
   }
   public Integer getValue() { return value; }
      public void setValue(Integer value) {
   this.value = value;
   }
  }
  </code></pre>
  
  <p><em>Test.java (Main class)</em></p>
  
  <pre><code>public class Test {
   public static void main(String[] args){
         Integer i = new Integer(1);
    Data d = new Data(i);
    GenericPeer.print(d);
        }
  }
  </code></pre>