JNI: arrays inside objects

Discussion in 'Java' started by hash.q, Oct 21, 2008.

  1. hash.q

    hash.q Guest

    Hello,

    I am calling a native function from Java passing an object that
    contains an array of strings.

    In C , I would like to change this array and return it back to java,
    how do i do this?
    I have read sun's documentation, but they never talk about this. any
    help would be appreciated.

    thanks,
    Hashim.
     
    hash.q, Oct 21, 2008
    #1
    1. Advertising

  2. On Tue, 21 Oct 2008 15:10:14 -0700 (PDT), hash.q wrote:
    > I am calling a native function from Java passing an object that
    > contains an array of strings.
    >
    > In C , I would like to change this array and return it back to java,
    > how do i do this? I have read sun's documentation, but they never
    > talk about this. any help would be appreciated.


    Of course the documentation does not describe every possible scenario,
    but you just need to understand how to manipulate objects.

    The general mechanism goes like this:

    - get the class from the object passed to your method (GetObjectClass)
    - get the field id of the String array from the class (GetFieldID)

    If you mean you want to change the contents of the String array:

    - with the field id and the object, get the array itself (GetObjectField)
    - do what you want with the array elements using various array
    functions (Get/SetObjectArrayElement, NewStringUTF, etc).

    If you mean that you want to replace the array in the object:

    - create the replacement array (NewObjectArray, NewStringUTF etc)
    - assign the new array to the field in the object (SetObjectField)

    /gordon

    --
     
    Gordon Beaton, Oct 22, 2008
    #2
    1. Advertising

  3. hash.q

    Guest

    On Oct 22, 6:10 am, "hash.q" <> wrote:
    > Hello,
    >
    > I am calling a native function from Java passing an object that
    > contains an array of strings.
    >
    > In C , I would like to change this array and return it back to java,
    > how do i do this?
    > I have read sun's documentation, but they never talk about this. any
    > help would be appreciated.
    >
    > thanks,
    > Hashim.


    Hello!

    I am not sure if this helps because I'm still studying java.
    But normally if I have any problems I log in this website
    http://java.sun.com/docs/books/tutorial/index.html
    Why don't you give this website a try.
    Hopefully this will help you.

    Best of luck.

    AsianDoll
     
    , Oct 22, 2008
    #3
  4. hash.q

    hash.q Guest

    On Oct 22, 4:45 am, wrote:
    > On Oct 22, 6:10 am, "hash.q" <> wrote:
    >
    > > Hello,

    >
    > > I am calling a native function from Java passing an object that
    > > contains an array of strings.

    >
    > > In C , I would like to change this array and return it back to java,
    > > how do i do this?
    > > I have read sun's documentation, but they never talk about this. any
    > > help would be appreciated.

    >
    > > thanks,
    > > Hashim.

    >
    > Hello!
    >
    > I am not sure if this helps because I'm still studying java.
    > But normally if I have any problems I log in this websitehttp://java.sun.com/docs/books/tutorial/index.html
    > Why don't you give this website a try.
    > Hopefully this will help you.
    >
    > Best of luck.
    >
    > AsianDoll



    Thanks guys, it is working now.
     
    hash.q, Oct 22, 2008
    #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:
    886
    Alex Hunsley
    Nov 4, 2003
  2. Pasturel Jean-Louis

    Porting JNI Windows under JNI LINUX + Wine ?

    Pasturel Jean-Louis, Feb 29, 2004, in forum: Java
    Replies:
    5
    Views:
    947
    Pasturel Jean-Louis
    Mar 3, 2004
  3. vasanth
    Replies:
    0
    Views:
    2,784
    vasanth
    Jan 25, 2005
  4. vasanth
    Replies:
    0
    Views:
    642
    vasanth
    Jan 25, 2005
  5. Philipp
    Replies:
    21
    Views:
    1,190
    Philipp
    Jan 20, 2009
Loading...

Share This Page