JNI: Calling methods that return byte[]

Discussion in 'Java' started by Alan Cabrera, Jan 23, 2005.

  1. Alan Cabrera

    Alan Cabrera Guest

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


    Regards,
    Alan
     
    Alan Cabrera, Jan 23, 2005
    #1
    1. Advertising

  2. 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
     
    Gordon Beaton, Jan 23, 2005
    #2
    1. Advertising

  3. Alan Cabrera

    Alan Cabrera Guest

    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" <> wrote in message
    news:41f407a8$...
    > 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
     
    Alan Cabrera, Jan 23, 2005
    #3
  4. 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
     
    Gordon Beaton, Jan 24, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex Hunsley

    IBM's JNI fails where Sun's JNI works

    Alex Hunsley, Nov 3, 2003, in forum: Java
    Replies:
    4
    Views:
    851
    Alex Hunsley
    Nov 4, 2003
  2. Oliver Wong
    Replies:
    14
    Views:
    1,629
    Chris Uppal
    Jun 13, 2006
  3. Oltmans
    Replies:
    6
    Views:
    349
    Terry Reedy
    Mar 11, 2009
  4. Rhino
    Replies:
    49
    Views:
    1,035
  5. Kenneth McDonald
    Replies:
    5
    Views:
    324
    Kenneth McDonald
    Sep 26, 2008
Loading...

Share This Page