Note that there are some explanatory texts on larger screens.

plurals
  1. PONewGlobalRef for jmethodID
    primarykey
    data
    text
    <p>I have a problem with something that otherwise seems to be an easy task. I have a native method which returns a jobjectArray of instances of a Java class (custom). What I do is get the jclass for my class I want to instantiate and return and then get the jmethodID for it's constructor.</p> <p>The native method's signature is:</p> <pre><code>JNIEXPORT jobjectArray JNICALL Java_com_mn_rootscape_utils_NativeMethods_getFilesPermissions( JNIEnv* env, jobject thizz, jobjectArray filePathsArray ) </code></pre> <p>The namespace and constructor signature are defined as follows:</p> <pre><code>const char* kFilePermissionInfoPath = "com/mn/rootscape/utils/FilePermissionInfo"; const char* kFilePermInfoConstructorSig = "(IIIIIJJJLjava/lang/String;Ljava/lang/String;ZLjava/lang/String;)V"; </code></pre> <p>For the jclass and jmethodID I'm following the instructions posted <a href="http://android-developers.blogspot.ro/2011/11/jni-local-reference-changes-in-ics.html" rel="noreferrer">here</a>. So I'm getting their global references so I can use them later. Please note that I do not have an oninit in my lib yet, the code is just for testing for now.</p> <p>The problem is that I get a segmentation fault when I try to retrieve the global reference for the jmethodID.</p> <p>The code that does this is:</p> <pre><code>jclass filePermInfoCls = (*env)-&gt;FindClass(env, kFilePermissionInfoPath); if(!filePermInfoCls) { LOGE("getFilesPermissions: failed to get class reference."); return NULL; } gFilePermInfoClass = (jclass)(*env)-&gt;NewGlobalRef(env, filePermInfoCls); LOGI("got gFilePermInfoClass"); jmethodID filePermInfoClsConstructor = (*env)-&gt;GetMethodID(env, gFilePermInfoClass, "&lt;init&gt;", kFilePermInfoConstructorSig1); if(!filePermInfoClsConstructor) { LOGE("getFilesPermissions: failed to get method reference."); return NULL; } gFilePermInfoClsConstructor = (jmethodID)(*env)-&gt;NewGlobalRef(env, filePermInfoClsConstructor); LOGI("got gFilePermInfoClsConstructor"); </code></pre> <p>The actual error is:</p> <blockquote> <p>06-14 09:17:26.648: W/dalvikvm(26012): Invalid indirect reference 0x4c0bdc40 in decodeIndirectRef 06-14 09:17:26.648: E/dalvikvm(26012): VM aborting</p> </blockquote> <p>gFilePermInfoClass and gFilePermInfoClsConstructor are global jclass and jmethodID objects, to hold the global refs.</p> <p>Any help in this would be appreciated.</p> <p>Thanks</p>
    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.
 

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