JNI - Tablemodel
Hello!
I made a Tablemodel in Java with native methods (getValueAt, ...)
which are implemented in C/C++.
My question is:
How can I return a Integer, Double or Boolean object in the getValueAt
method in C/C++, if the return type is a jobject?
JNIEXPORT jobject JNICALL Java_JNITableModel_getValueAt (JNIEnv *env, jobject obj, jint i, jint j)
[383 byte] By [
fritzala] at [2007-11-26 16:41:41]

# 1
> Hello!
> I made a Tablemodel in Java with native methods
> (getValueAt, ...)
> which are implemented in C/C++.
> My question is:
> How can I return a Integer, Double or Boolean object
> in the getValueAt
> method in C/C++, if the return type is a
> jobject?
Use the wrapper classes: java.lang.Integer, java.lang.Double, and java.lang.Boolean.
# 2
I have already done this, but it doesn't work:
//sample Integer Object
intcls = (*env)->FindClass(env, "java.lang.Integer");
if (intcls == NULL) //ERROR
jmid = (*env)->GetMethodID(env, jcls, "<init>","()V");
if (jmid == NULL) //ERROR
jobj = (*env)->NewObject(env, jcls, jmid, intvalue);
return jobj;
Please tell me if there's something wrong.
thanks for your help
Message was edited by:
Fritzal
# 3
> I have already done this, but it doesn't work:
>
> > //sample Integer Object
> intcls = (*env)->FindClass(env,
> "java.lang.Integer");
> if (intcls == NULL) //ERROR
> jmid = (*env)->GetMethodID(env, jcls,
> "<init>","()V");
> if (jmid == NULL) //ERROR
> jobj = (*env)->NewObject(env, jcls, jmid, intvalue);
> return jobj;
>
>
> Please tell me if there's something wrong.
There is. You have retrieved the wrong method ID.
If you use the javap command with the -s option, you can see the proper signature for the constructor that takes an int parameter:
javap -s java.lang.Integer
Compiled from "Integer.java"
public final class java.lang.Integer extends java.lang.Number implements java.la
ng.Comparable{
...
...
...
public java.lang.Integer(int);
Signature: (I)V
...
...
...
Note the part between the parentheses. The signature you used retrieves the ID for the constructor that takes no arguments. You then call it using arguments and it fails.
Jim S.