3

I am trying to call a java method from cpp. I seem to have no problem using strings, int, etc. One problem I am having those is passing an int array parameter over. Can someone tell me what I did wrong? I apologize if it is a very small error and I just totally missed it.

JNIEXPORT void JNICALL
Java_basket_menu_MenusActivity_submitInfo(JNIEnv *, jclass){
    int placement[2] = { 5, 4 };

    jclass cls = env->FindClass("basket/menu/MenusActivity");
    jmethodID mid2 = env->GetStaticMethodID(cls, "PlaceMe", "([I)V");
    env->CallStaticVoidMethod(cls, mid2, placement); 
}

1 Answer 1

5

You need to create a jintArray and copy the contents of placement to it:

    jintArray arr = env->NewIntArray(2);
    env->SetIntArrayRegion(arr, 0, 2, placement);
    env->CallStaticVoidMethod(cls, mid2, arr); 

Refer to the documentation for more information about these functions.

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

1 Comment

Thank you Michael.

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.