Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to return int array from Java to JNI

I have to call a Java method from JNI. This Java method returns int array (int[] simpleMethod()). How to call this from JNI to get the array as a return value? I know how to do this when method returns void/String/int/etc but couldn't find anything with arrays. I have some ideas how to work around this but maybe there is simple answer.

like image 480
Marcin Bak Avatar asked Dec 02 '11 15:12

Marcin Bak


1 Answers

Use CallObjectMethod. For example:

jmethodID myMethod = (*env)->GetMethodID(myClass, "myMethod", "()[I");
jintArray retval = (jintArray) (*env)->CallObjectMethod(myObject, myMethod);
like image 196
Edward Thomson Avatar answered Nov 15 '22 06:11

Edward Thomson