Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You haven't mentioned the target class name and the target method signature. So consider, for example, <a href="http://developer.android.com/reference/java/lang/StringBuilder.html#append%28java.lang.String%29" rel="nofollow">java.lang.StringBuilder.append(java.lang.String)</a> method.</p> <pre><code>// First lets assume you have already received the next variables void foo( JNIEnv* env, jobject obj ) { // Call StringBuilder.append() method } </code></pre> <p>Now you need the class name and the method signature (according to <a href="http://docs.oracle.com/javase/1.5.0/docs/guide/jni/spec/types.html" rel="nofollow">docs</a>)</p> <pre><code>static char const StringBuilder_ClassName = "java/lang/StringBuilder"; static char const StringBuilder_append_MethodName = "append"; static char const StringBuilder_append_MethodSignature = "(Ljava/lang/String;)Ljava/lang/StringBuilder;"; </code></pre> <p>To call java method from JNI code you should obtain <code>jmethodID</code></p> <pre><code>static jclass StringBuilder_Class = 0; static jmethodID StringBuilder_append_Method = 0; void Init( JNIEnv* env ) { if( StringBuilder_Class == 0 ) { StringBuilder_Class = (*env)-&gt;FindClass( env, StringBuilder_ClassName ); // TODO: Handle error if class not found } if( StringBuilder_append_Method == 0 ) { StringBuilder_append_Method = (*env)-&gt;GetMethodID( env, StringBuilder_Class, StringBuilder_append_MethodName, StringBuilder_append_MethodSignature ); // TODO: Handle error if method not found } } void foo( JNIEnv* env, jobject obj ) { Init(); char* str; // str = ...; jstring jString = (*env)-&gt;NewStringUTF( env, str ); // Because StringBuild.append() returns object, you should call CallObjectMethod jobject ret = (*env)-&gt;CallObjectMethod( env, obj, jString ); // Here you can release local references, i.e. // (*env)-&gt;DeleteLocalRef( env, ret ); // (*env)-&gt;DeleteLocalRef( env, jString ); // But it is not necessary. Local references are released automatically when // thread returns from JNI code to Java code. // So you can ignore the returned value and not to release the jString local // reference, i.e. just call // (*env)-&gt;CallObjectMethod( env, obj, jString ); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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