Note that there are some explanatory texts on larger screens.

plurals
  1. POSending parameters to java via c++
    text
    copied!<p>My java class has a static function defined as follows:</p> <pre><code>public static void logEvent(final String eventName, final String jObject) { //Function data } </code></pre> <p>Now my cpp file has the following function</p> <pre><code>void PingoScreen::callApslarIntegration(){ char* eventName="bingo"; JniMethodInfo t; if (JniHelper::getStaticMethodInfo(t, "com/myapp/test/ApslarSetup","logEvent", "()V")) { t.env-&gt;CallStaticVoidMethod(t.classID, t.methodID); t.env-&gt;DeleteLocalRef(t.classID); } } </code></pre> <p>How can i send two string params to the JAVA function via JNI ?</p> <p>Kind Regards</p> <p>===============================================================</p> <pre><code>void PingoScreen::callApsIntegration() { JniMethodInfo t; if (JniHelper::getStaticMethodInfo(t, "com/myapp/test/ApslarSetup", "logJSONEvent", "()V")) { const char* cstr1 = "Test1"; const char* cstr2 = "Test2"; jstring jstr1 = t.env-&gt;NewStringUTF(cstr1); jstring jstr2 = t.env-&gt;NewStringUTF(cstr2); t.env-&gt;CallStaticVoidMethod(t.classID, t.methodID,jstr1,jstr2); t.env-&gt;DeleteLocalRef(t.classID); } } </code></pre> <p>The above function causes a crash ?</p> <p>==================================</p> <p>Finally got it to work</p> <pre><code>void PingoScreen::callApslarIntegration() { JniMethodInfo t; if (JniHelper::getStaticMethodInfo (t, "com/nbs/test/ApslarSetup", "logJSONEvent", "(Ljava/lang/String;Ljava/lang/String;)V")) { const char* cstr1 = "Test1"; const char* cstr2 = "Test2"; jstring jstr1 = t.env-&gt;NewStringUTF(cstr1); jstring jstr2 = t.env-&gt;NewStringUTF(cstr2); t.env-&gt;CallStaticVoidMethod(t.classID, t.methodID,jstr1,jstr2); t.env-&gt;DeleteLocalRef(t.classID); } } </code></pre> <p>The crash was due to the line</p> <pre><code>if (JniHelper::getStaticMethodInfo (t, "com/nbs/test/ApslarSetup", "logJSONEvent", "(Ljava/lang/String;Ljava/lang/String;)V")) </code></pre> <p>The signiture had to be <code>Ljava/lang/String;Ljava/lang/String;</code> and not <code>Ljava/lang/String;Ljava/lang/String</code> (notice the last semi-colon)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload