Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > JNI: Calling methods that return byte[]

Reply
Thread Tools

JNI: Calling methods that return byte[]

 
 
Alan Cabrera
Guest
Posts: n/a
 
      01-23-2005
How can I call a method that returns a byte[] in JNI? How do I access those
bytes?


Regards,
Alan



 
Reply With Quote
 
 
 
 
Gordon Beaton
Guest
Posts: n/a
 
      01-23-2005
On Sun, 23 Jan 2005 11:58:02 -0800, Alan Cabrera wrote:
> 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

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
 
Reply With Quote
 
 
 
 
Alan Cabrera
Guest
Posts: n/a
 
      01-23-2005
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" <(E-Mail Removed)> wrote in message
news:41f407a8$(E-Mail Removed)...
> On Sun, 23 Jan 2005 11:58:02 -0800, Alan Cabrera wrote:
>> 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
>
> --
> [ do not email me copies of your followups ]
> g o r d o n + n e w s @ b a l d e r 1 3 . s e



 
Reply With Quote
 
Gordon Beaton
Guest
Posts: n/a
 
      01-24-2005
On Sun, 23 Jan 2005 14:29:46 -0800, Alan Cabrera wrote:
> 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

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Design question - methods calling methods Rhino Java 49 05-29-2010 03:16 AM
calling class methods from class methods, help? Oltmans Python 6 03-11-2009 07:59 PM
Is there a way to find the class methods of a class, just like'methods' finds the instance methods? Kenneth McDonald Ruby 5 09-26-2008 03:09 PM
Avoid calling non-final methods in a constructor: Applies to static methods too? Oliver Wong Java 14 06-13-2006 09:18 AM
what value does lack of return or empty "return;" return Greenhorn C Programming 15 03-06-2005 08:19 PM



Advertisments