JNI - Getting a double array form Java

Discussion in 'Java' started by Edsoncv, Aug 17, 2006.

  1. Edsoncv

    Edsoncv Guest

    Hello
    I'm trying (without sucess :( ) to get a double array form Java using
    JNI.
    My function (in C++) calls "CallDoubleMethod" but put trash in my "C"
    double array. I'm doing somethig wrong but I don't know what. I check
    the values from Java and it is being calculated perfectly, I think the
    problem is in the array association (since I'm not a experienced
    programmer). Below is my code.

    jdouble *jacj = new jdouble[n];
    .....
    get class
    get method id
    get object and so on...

    *jacj = env->CallDoubleMethod(res_gradObj, getdataMetID);

    I'm almost sure that the problem is in the last line. Can someone
    please help me?
    Thanks
     
    Edsoncv, Aug 17, 2006
    #1
    1. Advertising

  2. Edsoncv

    Edsoncv Guest

    I forgot to say that my function in Java returns a double array.
    Thanks


    Edsoncv wrote:
    > Hello
    > I'm trying (without sucess :( ) to get a double array form Java using
    > JNI.
    > My function (in C++) calls "CallDoubleMethod" but put trash in my "C"
    > double array. I'm doing somethig wrong but I don't know what. I check
    > the values from Java and it is being calculated perfectly, I think the
    > problem is in the array association (since I'm not a experienced
    > programmer). Below is my code.
    >
    > jdouble *jacj = new jdouble[n];
    > ....
    > get class
    > get method id
    > get object and so on...
    >
    > *jacj = env->CallDoubleMethod(res_gradObj, getdataMetID);
    >
    > I'm almost sure that the problem is in the last line. Can someone
    > please help me?
    > Thanks
     
    Edsoncv, Aug 17, 2006
    #2
    1. Advertising

  3. On 17 Aug 2006 07:40:44 -0700, Edsoncv wrote:
    > I'm trying (without sucess :( ) to get a double array form Java
    > using JNI.

    [...]
    > *jacj = env->CallDoubleMethod(res_gradObj, getdataMetID);
    >
    > I'm almost sure that the problem is in the last line. Can someone
    > please help me?


    "Array of double" is not a primitive type. Use CallObjectMethod()
    instead:

    jdoubleArray jacj = CallObjectMethod(...);

    /gordon

    --
    [ don't email me support questions or followups ]
    g o r d o n + n e w s @ b a l d e r 1 3 . s e
     
    Gordon Beaton, Aug 17, 2006
    #3
  4. Edsoncv

    Edsoncv Guest

    Ok, it worked. Thanks again.!! :)

    Gordon Beaton wrote:
    > On 17 Aug 2006 07:40:44 -0700, Edsoncv wrote:
    > > I'm trying (without sucess :( ) to get a double array form Java
    > > using JNI.

    > [...]
    > > *jacj = env->CallDoubleMethod(res_gradObj, getdataMetID);
    > >
    > > I'm almost sure that the problem is in the last line. Can someone
    > > please help me?

    >
    > "Array of double" is not a primitive type. Use CallObjectMethod()
    > instead:
    >
    > jdoubleArray jacj = CallObjectMethod(...);
    >
    > /gordon
    >
    > --
    > [ don't email me support questions or followups ]
    > g o r d o n + n e w s @ b a l d e r 1 3 . s e
     
    Edsoncv, Aug 17, 2006
    #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. Pasturel Jean-Louis

    Porting JNI Windows under JNI LINUX + Wine ?

    Pasturel Jean-Louis, Feb 29, 2004, in forum: Java
    Replies:
    5
    Views:
    906
    Pasturel Jean-Louis
    Mar 3, 2004
  3. vasanth
    Replies:
    0
    Views:
    2,702
    vasanth
    Jan 25, 2005
  4. Sydex
    Replies:
    12
    Views:
    6,505
    Victor Bazarov
    Feb 17, 2005
  5. Replies:
    5
    Views:
    433
    James Kanze
    Jun 27, 2008
Loading...

Share This Page