Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

pass Hashtable to JNI as jobject and get value for a key

843829Apr 3 2008 — edited Apr 8 2008
Hi,

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);
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 6 2008
Added on Apr 3 2008
3 comments
488 views