Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JNI Calling Java Method With Array Parameter

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); 
}
like image 231
Liquified Modding Avatar asked Dec 02 '25 15:12

Liquified Modding


1 Answers

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.

like image 95
Michael Avatar answered Dec 05 '25 19:12

Michael



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!