I have an android project that uses a c++ library and i need to send an object array to the c++ code.
This is my Java native bind code
class MyLib {
public static native void testArray(String[] array);
}
This is how i call it
...
MyLib.testArray(new Object[20]);
...
And this is my c++ jni code:
JNIEXPORT void JNICALL Java_com_android_mypackage_MyLib_testArray(JNIEnv * env, jobjectArray arr) {
__android_log_print(ANDROID_LOG_INFO,"test","test array!!!!!!!!");
int count = env->GetArrayLength(arr);
__android_log_print(ANDROID_LOG_INFO,"test","array length %d", count);
for (int i=0; i<count; i++) {
__android_log_print(ANDROID_LOG_INFO,"test","--- get item %d", i);
jstring jkey = (jstring) env->GetObjectArrayElement(arr, i);
__android_log_print(ANDROID_LOG_INFO,"test","item %d", i);
env->DeleteLocalRef(jkey);
}
}
When i execute that, logcat shows this and execution ends with sigsev 11
JNI WARNING: jarray arg has wrong type (expected array, got Ljava/lang/Class;) in Lcom/android/mypackage/MyLib;.testArray:([Ljava/lang/Object;)V (GetArrayLength)
Any ideas why my array reference appears to be a class reference? I have no problems with arrays of native types, only with objects.