Posted By:
planet_saro
Posted On:
Thursday, April 3, 2008 02:00 PM
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, jobje
More>>
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
", jstr);
}
<<Less