dcsimg
pass Hashtable to JNI as jobject
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

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

Re: pass Hashtable to JNI as jobject

Posted By:   Anonymous  
Posted On:   Monday, April 7, 2008 05:01 AM

Exactly what u need?
I think you pointer is not getting proper object to invoke the method. I will suggest try to access another method just to print anything, if it doesn't work then it's problem not getting access the method, then u will find the reason behind that. Let me know if u have any more doubt.
About | Sitemap | Contact