JNI: Calling methods that return byte[]

A

Alan Cabrera

How can I call a method that returns a byte[] in JNI? How do I access those
bytes?


Regards,
Alan
 
A

Alan Cabrera

Duh, I guess

jbyteArray arr = (jbyteArray) (*env)->CallObjectMethod(env, obj, mid, arg);

will work. However, I'm getting an EXCEPTION_ACCESS_VIOLATION when I call
jobject tmp = env->CallObjectMethod(iaObj,
env->GetMethodID(env->FindClass("java/net/InetAddress"), "getAddress",
"()[B"));

But this seems to work fine

jobject tmp = env->CallNonvirtualObjectMethod(iaObj,
env->FindClass("java/net/InetAddress"),
env->GetMethodID(env->FindClass("java/net/InetAddress"), "getAddress",
"()[B"));
in that I believe that it's calling InetAddress' method since I get 0,
which is what InetAddress' implmentation returns.

I have confirmed that I have a valid iaObj which points to an instance who's
parent class is InetAddress, I can get its address field.


Gordon Beaton said:
How can I call a method that returns a byte[] in JNI?

jbyteArray arr = (*env)->CallObjectMethod(env, obj, mid, arg);
How do I access those bytes?

SetByteArrayRegion(), GetByteArrayRegion(), etc.

/gordon
 
G

Gordon Beaton

However, I'm getting an EXCEPTION_ACCESS_VIOLATION when I call
jobject tmp = env->CallObjectMethod(iaObj,
env->GetMethodID(env->FindClass("java/net/InetAddress"), "getAddress",
"()[B"));

In that case I'd suspect an earlier error in your code. You have
managed to corrupt the JVMs memory before even reaching this section
of code. If you write a short method that does only this one thing, I
think you'll find that it does work.

What happens if you use GetObjectClass(iaObj) instead of FindClass()?

/gordon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top