3
JNIEXPORT jobject JNICALL Java_com_example_androidhellojni_FooFragmentTab_getUserList(JNIEnv *env, jobject obj)
{
jint i;
jclass cls_arraylist = (*env)->FindClass(env, "java/util/ArrayList");
jmethodID init_arraylist = (*env)->GetMethodID(env, cls_arraylist, "<init>", "()V");
jobject obj_arraylist = (*env)->NewObject(env, cls_arraylist, init_arraylist, "");
if (obj_arraylist == NULL) LOGD("obj_arrlist fail");
jmethodID arraylist_add = (*env)->GetMethodID(env, cls_arraylist, "add", "(Ljava/lang/Object;)Z");
if (arraylist_add == NULL) LOGD("arraylist_add fail");
jclass cls_int = (*env)->FindClass(env, "java/lang/Integer");
jmethodID init_int = (*env)->GetMethodID(env, cls_int, "<init>", "(I)V");
for (i = 0; i < 10; i++) {
jobject obj_int = (*env)->NewObject(env, cls_int, init_int, i);
(*env)->CallObjectMethod(env, obj_arraylist, arraylist_add, obj_int);
}
return obj_arraylist;
}
這是我的示例代碼從C得到回報的ArrayList到Java(Android版),但編譯和運行存在一些錯誤信息,如:的Android NDK獲得ArrayList的錯誤
art/runtime/check_jni.cc:65] JNI DETECTED ERROR IN APPLICATION: the return type of CallObjectMethod does not match boolean java.util.ArrayList.add(java.lang.Object)
art/runtime/check_jni.cc:65] in call to CallObjectMethod
art/runtime/check_jni.cc:65] from java.util.ArrayList com.example.androidhellojni.FooFragmentTab.getUserList()
謝謝!有用 – causemx