How to use JNI to call JAVA method from C -


i want use jni (java native interface) call specific java setter method, passing short[] buffer parameter.

java method implimentation looks follows:

public void setpcmleft(short[] data) { pcm_l = data; } 

from inside c function how can call method using jni.

my code looks this:

void java_com_companyname_lame_lameactivity_lamedecode(jnienv *env, jobject jobj) {     jclass class = (*env)->getobjectclass(env, jobj);      if (class != null) {          jmethodid setleftdatatid = (*env)->getmethodid(env, class, "<setpcmleft>", "void(v)");         if (setleftdatatid == null) {             logd("(lame) no method setleftdata");         }       }  } 

when run this, setleftdataid allays null.

note jobj parameter object being passed in contains setpcmleft implementation.

in call getmethodid(), method name not need angle brackets, , signature needs match java method.

jmethodid setleftdatatid = (*env)->getmethodid(env, class, "setpcmleft", "([s)v"); 

in general, signature of form ( arg-types ) ret-type, encoded specified in link below. argument short[], encoded [s. return type v void.

more information available in chapter 3 of oracle jni guide.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -