我想通過jni將java樹形圖傳遞給c。我稱之爲本地方法:JNI將樹形圖從java傳遞到c
public native int getEuklid(TreeMap<int,short[]> map);
static {
System.loadLibrary("Euklid");
}
現在在我的c文件中,我想訪問地圖中的元素。我怎麼能做到這一點。這是我c文件中的頭文件:
JNIEXPORT int JNICALL
Java_Main_getEuklid (JNIEnv *env, jobject o, jobject o2)
其中o2是樹形圖。我該如何處理像java中的treemap那樣的jobject?
編輯:
哪裏是我的錯?:
JNIEXPORT int JNICALL
Java_Main_getEuklid (JNIEnv *env, jobject o, jobject o2){
jclass cls = env->GetObjectClass(o2) ;
jmethodID mGetValue = env->GetMethodID(cls, "keySet","()Ljava/util/Set;");
jobject value = env->CallObjectMethod(o2, mGetValue)
我變成了:
In function ‘Java_Main_getEuklid’:
11: error: request for member ‘GetObjectClass’ in something not a structure or union
12: error: request for member ‘GetMethodID’ in something not a structure or union
13: error: request for member ‘CallObjectMethod’ in something not a structure or union
我在C真正的新和我想要測試的東西,所以我希望你能幫我。
相關:http://stackoverflow.com/questions/4844022/jni-create-hashmap和http://stackoverflow.com/questions/5641499/making-generic-calls-with-java-jni-and-c – Cratylus 2013-04-21 17:38:36
我已經編輯我的文章 – bladepit 2013-04-21 17:52:02