4

see i have native function in nativeLib

 public native int [] getArrayNative();

which i am using like this

 private static int[] DEMO_NODES;

 DEMO_NODES =  nativeLib.getArrayNative();

in c code it has

JNIEXPORT jintArray JNICALL Java_com_testing_NativeLib_getArrayNative
  (JNIEnv *env, jobject obj) {

    int array[] = { 0, 1, 0, 1, 2, 1, 2, 3, 2, 3, 1, 2, 1, 2, 3, 2, 3, 1, 2 };
    jintArray temp = (*env)->NewIntArray(env,20);
    temp[0] = array[0];   // gives error
    return temp;    
}

here i want to return whole arry[] but i can not understand how to do that. here i have taken new array temp inside that tried to copy value of arry[] but it shows error. so how to do that

1 Answer 1

5

Use SetIntArrayRegion to fill the array, jintArray ist just some magic internal structure, nothing you can access using indices.

Prototype void SetArrayRegion(JNIEnv *env, array, jsize start, jsize len, *buf);

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

Comments

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.