How to cast uint8_t * to jbyteArray jni android

How to cast uint8_t * to jbyteArray jni android - Hello friend inabnomaniiyaha, In the article that you read this time with the title How to cast uint8_t * to jbyteArray jni android, we have prepared this article well for you to read and take information in it. hopefully the contents of the post Artikel Android,what we write you can understand. Alright, happy reading.

Judul : How to cast uint8_t * to jbyteArray jni android
link : How to cast uint8_t * to jbyteArray jni android

Baca juga


How to cast uint8_t * to jbyteArray jni android

 I am working on an Android library that uses some c/c++ code.

I apparently have some sort of coding error that only happens to error out on runtime.

The error: JNI DETECTED ERROR IN APPLICATION: use of invalid jobject 0x7d61e62000.

jni android

This is the JNI code I am using to call the C code.

JNIEXPORT jbyteArray JNICALL

Java_com_comp_complibrary_api_initializeProduct(JNIEnv *env, jobject 

                                                    instance,

                                                    jbyteArray buffer_) {

    jbyte *buffer = env->GetByteArrayElements(buffer_, NULL);


    jbyteArray rv = (jbyteArray) initializeProduct((uint8_t *) buffer);


    env->ReleaseByteArrayElements(buffer_, buffer, 0);

    return rv;

}

initializeProduct returns a uint8_t *.

If I understand things correctly then I should be able to cast the return value to a jbyteArray and then be able to assign that to a byte[] in one of my java classes. However, this is not the case.

byte[] defend = (byte[]) initializeProduct(bufferByteArray);

You will notice that a jbyteArray can be cast to a uint8_t * as I am passing one in as a parameter to initializeProduct. Stepping through the c code I can confirm this to be true.

What is the correct way to convert/cast uint8_t * to jbyteArray?

Non sequitur. Just because you can cast something doesn't imply that it actually becomes that. You need to use GetByteArrayElements() or GetByteArrayRegion() to get the data out of the jbyteArray for your C code, followed by the appropriate ReleaseXXX() call when done.



That's the articleHow to cast uint8_t * to jbyteArray jni android

That's it for the article How to cast uint8_t * to jbyteArray jni android this time, hopefully can be useful for all of you. well, see you in another article post.

You are now reading the articleHow to cast uint8_t * to jbyteArray jni android with link addresshttps://inabnonapudyawanabing.blogspot.com/2021/04/how-to-cast-uint8t-to-jbytearray-jni.html

0 Response to "How to cast uint8_t * to jbyteArray jni android"

Post a Comment

Tips Tricks for Android Phone

Tips & Tricks for Android Phone is a free android app and Collection of Tips and Tricks related to using your android mobile device lik...