title: How to use JNI registerNatives inside c++ class?
body: <p>I have a c++ class called androidGPS with public methods and variables. Inside this class I am using JNI to calls some java code. But I am stuck in the registerNatives function.</p>
  
  <p>My c++ class has this void method:</p>
  
  <pre><code>void LocationChanged(JNIEnv* env, jobject object, jstring paramsString);
  </code></pre>
  
  <p>Implemented in this way:</p>
  
  <pre><code>void androidGPS::LocationChanged(JNIEnv*, jobject, jstring paramsString)
  {
      const char * nativeString = currEnv-&gt;GetStringUTFChars(paramsString, 0);
  
      QString qstring(nativeString);
      QStringList res;
      res &lt;&lt; qstring;
      emit newReadAvailable(res);
  }
  </code></pre>
  
  <p>The Java class that I try to link to has the following method:</p>
  
  <pre><code>public static native void sndonLocationChanged(String currLocation);
  </code></pre>
  
  <p>I am declaring the JNINativeMethods as a local variable before calling the register natives like:</p>
  
  <pre><code>JNINativeMethod methods[] =
  {
      {
           "sndonLocationChanged",
           "(Ljava/lang/String;)V",
           (void *)&amp;androidGPS::LocationChanged
      }
  };
  </code></pre>
  
  <p>The register natives call is this:</p>
  
  <pre><code>int numMethods;
      numMethods = sizeof(methods) / sizeof(methods[0]);
      if (currEnv-&gt;RegisterNatives(listenerClass, methods, numMethods) &lt; 0)
      {
          if (currEnv-&gt;ExceptionOccurred())
          {
              classError = true;
              emit error("JNI--Error running RegisterNatives");
              stopGPSService();
              return false; //Return with error
          }
          else
          {
              emit error("JNI--Error running RegisterNatives");
              stopGPSService();
              return false; //Return with error
          }
      }
  </code></pre>
  
  <p>The compiler gives me the warning:</p>
  
  <blockquote>
    <p>warning: converting from 'void
    (androidGPS::<em>)(JNIEnv</em>, _jobject*,
    _jstring*)' to 'void*'</p>
  </blockquote>
  
  <p>The c++ application crashes when I call the function sndonLocationChanged() in the class through JNI. I cannot see the error in the c++, but the Dalvik does not generate an error.</p>
  
  <p>I guess is because I am not calling properly registerNatives or not declaring properly the methods (hence the warning).</p>
  
  <p>If I declare LocationChanged static as:</p>
  
  <pre><code>static jboolean LocationChanged(JNIEnv* env, jobject object, jstring paramsString);
  </code></pre>
  
  <p>It does not fail but I cannot pass paramsString into class members!</p>
  
  <p>Any idea how can I fix this?</p>
  
  <p>Many thanks,</p>
  
  <p>Carlos.</p>