title: JNI Function Causing Android App to Crash
body: <p>I have the following JNI function that sends an event to my Java code.</p>
  
  <pre><code>void onIncrementAchievement(unsigned char _iArgumentCount, const void *_pArguments, void *_pUserData){
  JNIEnv *pJNIEnv = GetJNIEnv();
  if (pJNIEnv){
  
          if ( _pArguments &amp;&amp; ( _iArgumentCount &gt; 0 ) ){
                  const S3DX::AIVariable *pVariables = (const S3DX::AIVariable *)_pArguments ;
  
                  if(_iArgumentCount != 2)
                          LOGI("INCORRECT NUMBER OF PARAMETERS");
                  else{
                          if(pVariables[0].GetType() == S3DX::AIVariable::eTypeString){
                                  // CHANGE ME!
                                  jclass pJNIActivityClass = pJNIEnv-&gt;FindClass ( "com/nurfacegames/testgame01/TestGame01" );
  
                                  if(pJNIActivityClass == NULL)
                                          LOGI("jclass was null!?!");
                                  else{
                                          jmethodID pJNIMethodID = pJNIEnv-&gt;GetStaticMethodID(pJNIActivityClass, "onIncrementAchievement", "(Ljava/lang/String;Ljava/lang/Integer;)V");
  
                                          if(pJNIMethodID == NULL)
                                                  LOGI("jmethodID was null!?!?");
                                          else{
                                                  //Create a new string
                                                  jstring arg;
                                                  arg = pJNIEnv-&gt;NewStringUTF(pVariables[0].GetStringValue());
  
                                                  jint arg2 = pVariables[1].GetNumberValue();
  
                                                  //Call the method and pass the string parameter along
                                                  pJNIEnv-&gt;CallStaticVoidMethod(pJNIActivityClass, pJNIMethodID, arg, arg2);
                                                  //Free the string
                                                  pJNIEnv-&gt;DeleteLocalRef(arg);
                                          }
                                  }
                          }
                  }
          }
  }
  }
  </code></pre>
  
  <p>When I run my Android App, it force closes without even giving a single error in logcat, and when I compile with Ant, there are no compile errors. </p>
  
  <p>I hate to post such a vague question, but if someone has an idea what is wrong with my JNI code, please give me a hint. Thanks!</p>
  
  <p>The areas that I think have a problem (that I have been working on) are:</p>
  
  <pre><code> if(_iArgumentCount != 2)
                          LOGI("INCORRECT NUMBER OF PARAMETERS");
                  else{
  </code></pre>
  
  <p>and this section:</p>
  
  <pre><code>jint arg2 = pVariables[1].GetNumberValue();
  
  pJNIEnv-&gt;CallStaticVoidMethod(pJNIActivityClass, pJNIMethodID, arg, arg2);
  </code></pre>
  
  <p>Thanks!</p>