pass Hashtable to JNI as jobject and get value for a key
843829Apr 3 2008 — edited Apr 8 2008Hi,
Environment used - Linux, BEA JRockit JDK 1.5
Iam passing Hashtable to JNI and tried to access the get method of Hashtable in C by passing a key. Iam not gettting the value. instead it throws a dump and server exits.
the exception happens in the CallObjectMethod. iam getting a valid methodid though.
Java Code
----------------
Hashtable ht = new Hashtable();
ht.put("1", "one");
ht.put("2", "two");
public native String getHashValue(Hashtable ht);
C Code
----------
JNIEXPORT jstring JNICALL JNI_getHashValue(JNIEnv *env, jobject thisobj, jobject hashtable)
{
jclass hashClass=(*env)->GetObjectClass(env,hashtable);
jmethodID getMethod = (*env)->GetMethodID(env,hashClass,"get","(Ljava/lang/Object;)Ljava/lang/Object;");
jobject jkey = "1";
jobject jstr = (jobject)(*env)->CallObjectMethod(env,hashtable, getMethod,jkey);
printf("the string is %s \n", jstr);
}