5

I have a callback method in Java which is called by a native thread. One of the parameter of callback is an ArrayList object.

I am not able to get classref for ArrayList and its methods. Tried with "Ljava/util/ArrayList" but in vain. Please suggest a solution. thanks in advance

2 Answers 2

1

The class reference would be:

jclass cls = (*env)->FindClass(env, "java/util/ArrayList");

OR

jclass cls = (*env)->FindClass(env, "Ljava/util/ArrayList;");

You have an extra L in front of the java/util/ArrayList. In that case you also need to append a ;.

Sign up to request clarification or add additional context in comments.

Comments

1

I don't understood right, but i think you need anything like it:

void methodToCallJava(std::vector<YourClassCpp*> itens) {
    JNIEnv* env;
    YourSavedJVM->AttachCurrentThread(&env, NULL);
    jclass clazzDelegate = env->FindClass("your/delegate/class");
    jclass clazzYourClassJava = env->FindClass("your/class/java");
    jmethodID methodIdDelegate = env->GetMethodID(clazzDelegate, "delegateMethod", "(Ljava/util/ArrayList;)V");
    jobjectArray arrayListFromCpp = nullptr;
    jsize arrayListFromCppLength = itens.size();
    if (arrayListFromCppLength > 0)
        arrayListFromCpp = env->NewObjectArray(arrayListFromCppLength, clazzYourClassJava, methodToCreateJavaObjectFromCppObject(env, itens.at(0)));
    for (jsize c = 1; c < arrayListFromCppLength; c = c + 1)
        env->SetObjectArrayElement(arrayListFromCpp, c, methodToCreateJavaObjectFromCppObject(env, itens.at(c)));
    env->CallVoidMethod(this->delegate, methodIdDelegate, arrayListFromCpp);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.