Make New Java Object In JNI

R

res7cxbi

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?
 
G

Gordon Beaton

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top