I have a problem with something that otherwise seems like an easy task. I have my own method that returns jobjectArray instances of the Java class (custom). What I am doing is getting jclass for my class, which I want to create and return, and then get jmethodID for this constructor.
Native method signature:
JNIEXPORT jobjectArray JNICALL
Java_com_mn_rootscape_utils_NativeMethods_getFilesPermissions( JNIEnv* env, jobject thizz, jobjectArray filePathsArray )
The namespace and constructor signature are defined as follows:
const char* kFilePermissionInfoPath = "com/mn/rootscape/utils/FilePermissionInfo";
const char* kFilePermInfoConstructorSig = "(IIIIIJJJLjava/lang/String;Ljava/lang/String;ZLjava/lang/String;)V";
For jclass and jmethodID, I follow the instructions here . Therefore, I get their global links, so I can use them later. Note that I don't have oninit in my lib yet, the code is for testing at the moment.
The problem is that I get a segmentation error when I try to get a global reference for jmethodID.
Code that does this:
jclass filePermInfoCls = (*env)->FindClass(env, kFilePermissionInfoPath);
if(!filePermInfoCls)
{
LOGE("getFilesPermissions: failed to get class reference.");
return NULL;
}
gFilePermInfoClass = (jclass)(*env)->NewGlobalRef(env, filePermInfoCls);
LOGI("got gFilePermInfoClass");
jmethodID filePermInfoClsConstructor = (*env)->GetMethodID(env, gFilePermInfoClass, "<init>", kFilePermInfoConstructorSig1);
if(!filePermInfoClsConstructor)
{
LOGE("getFilesPermissions: failed to get method reference.");
return NULL;
}
gFilePermInfoClsConstructor = (jmethodID)(*env)->NewGlobalRef(env, filePermInfoClsConstructor);
LOGI("got gFilePermInfoClsConstructor");
Actual error:
06-14 09: 17: 26.648: W / dalvikvm (26012): Invalid indirect reference 0x4c0bdc40 in decodeIndirectRef 06-14 09: 17: 26.648: E / dalvikvm (26012): Cancel VM
gFilePermInfoClass and gFilePermInfoClsConstructor are global jclass and jmethodID objects for storing global references.
Any help on this would be appreciated.
thank