简体   繁体   English

JNI jintArray参数错误

[英]Jni jintArray params error

java: Java的

public int[] native getArray(int[] a); public int [] native getArray(int [] a);


c: C:

JNIEXPORT jintArray JNICALL 

 net_tq5_ArrayTest_getArray(JNIEnv *env, jobject obj, jintArray arr) {
return arr;
}

java: Java的

int[] a = new int[]{1,2,3,4,5};
int[] b = getArray(a);
for(int i=0; i<a.lenght; i++){
   Log.i("ArrayTest: ", "" + b[i]);
}

The result will be: 结果将是:

 ArrayTest: 0
 ArrayTest: 0
 ArrayTest: 0
 ...

Why ? 为什么呢 Help! 救命!

Your c header for function is incorrect. 您的c标头函数不正确。 Now it returns jint instead of jintArray. 现在,它返回jint而不是jintArray。 Try to regenerate the header and rebuild the library. 尝试重新生成标头并重建库。

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

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