Decision
The answer to question 1 .. Since jpSeed is jbyteArray , this means that you can get its length by calling the GetByteArrayElements( ... ) functions declared in JNI (you can read the documentation here ) here the correct code will be:
JNIEXPORT jint JNICALL Java_com_Test_Enroll( JNIEnv* env, jobject thiz, jbyteArray jpSeed ){ blobData_t* bd = malloc( sizeof(blobData_t) ); bd->length = (*env)->GetArrayLength( env, jpSeed ); ....... }
Answer to question 2. This code is bd->data[1] = jbyteArray; invalid because it will not be compiled. The correct solution for this part:
JNIEXPORT jint JNICALL Java_com_Test_Enroll( JNIEnv* env, jobject thiz, jbyteArray jpSeed ){ blobData_t* bd = malloc( sizeof(blobData_t) ); ....... jbyte* bytes = (*env)->GetByteArrayElements( env, jpSeed, 0 ); bd->data[1] = bytes[1]; }
And do not forget to free.
source share