简体   繁体   English

如何将int数组从Java返回到JNI

[英]How to return int array from Java to JNI

I have to call a Java method from JNI. 我必须从JNI调用Java方法。 This Java method returns int array (int[] simpleMethod()). 这个Java方法返回int数组(int [] simpleMethod())。 How to call this from JNI to get the array as a return value? 如何从JNI调用此方法将数组作为返回值? I know how to do this when method returns void/String/int/etc but couldn't find anything with arrays. 当方法返回void / String / int / etc但是找不到任何数组时,我知道如何做到这一点。 I have some ideas how to work around this but maybe there is simple answer. 我有一些想法如何解决这个问题,但也许有简单的答案。

Use CallObjectMethod . 使用CallObjectMethod For example: 例如:

jmethodID myMethod = (*env)->GetMethodID(myClass, "myMethod", "()[I");
jintArray retval = (jintArray) (*env)->CallObjectMethod(myObject, myMethod);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM