Make New Java Object In JNI

Discussion in 'Java' started by res7cxbi@verizon.net, Jan 27, 2006.

  1. Guest

    Im experimenting with this JNI thingy here....

    I want to try to make an AudioFormat object (as a jobject of course)
    and pass that to java.

    In the JNI book from Sun it says that you need to get the class that
    you will make instances from (FindClass), get the constructor
    (GetMethodID), then finally use NewObject to get the jobject and return
    it. Correct me if im wrong

    The Constructor i want to use in AudioFormat looks like this:

    AudioFormat(AudioFormat.Encoding encoding, float sampleRate, int
    sampleSizeInBits, int channels, int frameSize, float frameRate, boolean
    bigEndian)

    What do i do with the AudioFormat.Encoding argument?
     
    , Jan 27, 2006
    #1
    1. Advertising

  2. On 26 Jan 2006 22:03:30 -0800, wrote:
    > Im experimenting with this JNI thingy here....
    >
    > I want to try to make an AudioFormat object (as a jobject of course)
    > and pass that to java.
    >
    > In the JNI book from Sun it says that you need to get the class that
    > you will make instances from (FindClass), get the constructor
    > (GetMethodID), then finally use NewObject to get the jobject and
    > return it. Correct me if im wrong


    That's about right.

    A tip is to use "javap -s MyClass" to determine the correct method and
    constructor signatures to use in e.g. GetMethodID().

    Note too that you must include any package name when you specify the
    class, in a slightly different format than you're used to, e.g.:

    jclass cls = (*env)->FindClass(env, "java/lang/String").

    > The Constructor i want to use in AudioFormat looks like this:
    >
    > AudioFormat(AudioFormat.Encoding encoding, float sampleRate, int
    > sampleSizeInBits, int channels, int frameSize, float frameRate,
    > boolean bigEndian)
    >
    > What do i do with the AudioFormat.Encoding argument?


    If you need to pass an object (such as AudioFormat.Encoding) to any
    constructor or method, then of course you need to start by creating
    (or obtaining) one of those before you can invoke the constructor or
    method itself.

    /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 27, 2006
    #2
    1. Advertising

  3. Guest

    thanks!
     
    , Jan 28, 2006
    #3
    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. vasanth
    Replies:
    0
    Views:
    623
    vasanth
    Jan 25, 2005
  5. bgabrhelik
    Replies:
    0
    Views:
    818
    bgabrhelik
    Sep 29, 2009
Loading...

Share This Page