title: C++ and JNI - How to pass an array into a jfloatArray
body: <p>I have been messing with my own little project to teach myself the android ndk using c++ and jni but I can't figure out how to pass the data from a java float array to the c++ array. I have used the jni set up. Most the tutorials I find are either too simple and don't explain enough or are too complicated and go over my understanding at the moment. So, can some one just point me to a simple example of an array being passed from java to c++, then have some method/function performed on the data and sent back to java.   </p>
  
  <p>Heres my attempt so far but I have two errors left in the way. Im not sure if the rest of the syntax is up to par either but I don't see anything at compile time.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;Eigen/Dense&gt;
  #include &lt;math.h&gt;
  #include &lt;jni.h&gt;
  
  using namespace Eigen;
  
  Vector3f vec;
  Vector3f vec2;
  Vector3f vecRtrn;
  
  
  void vecLoad(float x, float y, float z, float x2, float y2, float z2){
  
  vec(0) = x;
  vec(1) = y;
  vec(2) = z;
  vec2(0) = x2;
  vec2(1) = y2;
  vec2(2) = z2;
  
  }
  
  void vecAdd(Vector3f vecA, Vector3f vecB){
  vecRtrn = vecA+vecB;
  }
  
  extern "C"
  {
  JNIEXPORT jfloatArray JNICALL Java_jnimath_act_JnimathActivity_test
  (JNIEnv *env, jobject obj, jfloatArray fltarray1, jfloatArray fltarray2){
  
  float array1[3];
  
  jfloatArray flt1 = fltarray1;
  jfloatArray flt2 = fltarray2;
  
  //flt1 = env-&gt;GetFloatArrayElements( fltarray1,0);
  //flt2 = env-&gt;GetFloatArrayElements( fltarray2,0);
  
  
  vecLoad(flt1[0], flt1[1], flt1[2], flt2[0], flt2[1], flt2[2]);
  vecAdd(vec, vec2);
  
  array1[0] = vecRtrn[0];
  array1[1] = vecRtrn[1];
  array1[2] = vecRtrn[2];
  
  return array1;
  
  };
  }
  </code></pre>
  
  <p>And these are the errors at compile time</p>
  
  <pre><code> $ /cygdrive/c/android-ndk-r7/ndk-build
  Compile++ thumb  : test &lt;= test.cpp
  jni/test.cpp: In function '_jfloatArray* Java_jnimath_act_JnimathActivity_test(JNIEnv*,    _jobject*, _jfloatArray*, _jfloatArray*)':
  jni/test.cpp:42: error: cannot convert '_jfloatArray' to 'float' for argument '1' to      'void vecLoad(float, float, float, float, float, float)'
  jni/test.cpp:49: error: cannot convert 'float*' to '_jfloatArray*' in return
  make: *** [obj/local/armeabi/objs/test/test.o] Error 1
  </code></pre>