title: Java JNI - Calling object method
body: <p>I'm currently programming an interface between some C++ code and Java using JNI.</p>
  
  <p>I'm getting some events in my GUI that I want to pass to a C++ event handler. </p>
  
  <p>I therefore call a function that I wrote in Java.</p>
  
  <pre><code>public void sendToEventQueue( AWTEvent evt ) {
    Mudkiptz.Main.fctC_sendEvent( evt );
  }
  </code></pre>
  
  <p>This method is in an abstract class EventHdl that I used as a super class for keyEventHandler in which I overload the keyTyped( KeyEvent) to send the KeyEvent to my C++ event handler with the method previously declared.</p>
  
  <p>My problem is that I want to get my keyEvent keyCode from the KeyEvent that I passed.</p>
  
  <pre><code>JNIEXPORT void JNICALL Java_Mudkiptz_Main_fctC_1sendEvent
  (JNIEnv* env, jclass, jobject evt) {
    // Obtenir les infos (Get information)
    jclass keyEventClass = env-&gt;FindClass("java/awt/event/KeyEvent");
  
    if( env-&gt;IsInstanceOf(evt, keyEventClass) ) {
      jmethodID getKeyCode = env-&gt;GetMethodID(keyEventClass, "getKeyCode", "()I");
      int keyCode = 0;
      keyCode = env-&gt;CallIntMethod(evt, getKeyCode);
    }
    // getInstance()
    Application::obtenirInstance()-&gt;getEventQueue()-&gt;push( evt );
  }
  </code></pre>
  
  <p>But it doesn't not work... :( I'm not used to JNI so it may be a easy mistake nevertheless I would really appreciate help.</p>
  
  <p>Edit: I should have been more precise. The method return but keyCode always equals zero when it should give the keyCode. thanks!</p>
  
  <p>Thanks!</p>