Posted By

jwielandt on 04/22/11


Tagged

java c++ jni


Versions (?)

jni init array from object


 / Published in: C++
 

  1. NIEXPORT jobject JNICALL Java_be_arrowup_argenta_CardReader_readCardMaestroNative(JNIEnv *env, jobject obj)
  2. {
  3. jclass cls = NULL;
  4. jobject jData = jniCreateObject (env, "Data", cls);
  5. if (jCardData == NULL || cls == NULL) {
  6. return NULL;
  7. }
  8. size_t byteArrayLength = 10;
  9.  
  10. //set the iso2 byte data
  11. jbyteArray jByteArray = env->NewByteArray(byteArrayLength);
  12. env->SetByteArrayRegion(isoByteArray, 0, byteArrayLength, (jbyte*)nativeByteArray);
  13.  
  14. jfieldID byteArrayId = env->GetFieldID(cls, "bArrayName", "[B");
  15.  
  16. env->SetObjectField(Data, byteArrayId, jByteArray);
  17.  
  18. }

Report this snippet  

You need to login to post a comment.