java - JNI GetMethodID not working for constructor of inner class -


i have class private subclass. want create instance of subclasss in jni wrapper , return it. i've googled , tried make work no success (methodid null). suggestions?

jniexport jobject jnicall java_some_class_some_jni_method(jnienv *env, jobject this) {         jclass cls = (*env)->findclass(env, "someclass$somesubclass");         if (cls == null)             printf("jclass error.");          jmethodid methodid = (*env)->getmethodid(env, cls, "<init>", "()v"); // -> problem!         if (methodid == null)             printf("jmethodid error.");          jobject obj = (*env)->newobject(env, cls, methodid);         if (obj == null)             printf("jobject error.");          return obj; } 

edit1: adding class definition:

public class someclass  {      private class somesubclass {              public somesubclass() {         }     ...     } ... } 

edit2: ok figured out need parent class in getmethodid signature, in example: jmethodid methodid = (*env)->getmethodid(env, cls, "<init>", "(lsomeclass;)v");

but exception_access_violation newobject function.

edit3: needed add calling class object/pointer newobject function: jobject obj = (*env)->newobject(env, cls, methodid, this);

constructor of nested class called properly.

you need parent class in getmethodid signature, in example: jmethodid methodid = (*env)->getmethodid(env, cls, "<init>", "(lsomeclass;)v");

and needed add calling class object/pointer newobject function: jobject obj = (*env)->newobject(env, cls, methodid, this);


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -