Bonjour,
J'ai défini une méthode native:
public static native int test(Map<Integer, Integer> mapNumDataCDFGNbBit);
ensuite je génère le prototype:
1 2 3 4 5 6 7
| /*
* Class: noiseEvaluationLib_natives_NEvalLibNatives
* Method: test
* Signature: (Ljava/util/Map;)I
*/
JNIEXPORT jint JNICALL Java_noiseEvaluationLib_natives_NEvalLibNatives_test
(JNIEnv *, jclass, jobject); |
Mon souci est que je n'arrive pas à utiliser la fonction "get" de la map afin de récupérer la valeur d'un élément (peut etre parce qu'il faudrait typer en object?)
voici mon impémentation de la fonction:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| /*
* Class: noiseEvaluationLib_natives_NEvalLibNatives
* Method: test
* Signature: (Ljava/util/Map;)I
*/
JNIEXPORT jint JNICALL Java_noiseEvaluationLib_natives_NEvalLibNatives_test
(JNIEnv *env, jclass class, jobject hashMap)
{
jint ret = 0;
printf("\n ici:\n");
// Get the HashMap Class
jclass jclass_of_hashmap = (*env)->GetObjectClass(env, hashMap);
printf("\n ici2:\n");
jmethodID getNumMethod = (*env)->GetMethodID(env, jclass_of_hashmap, "get", "(I)I");
printf("\n ici3:\n");
(*env)->CallIntMethod(env, hashMap, getNumMethod, 0);
printf("\n ici4:\n");
printf("\n ret trouve: %d", ret);
return ret;
} |
et ma fonction test:
1 2 3 4
| Map<Integer, Integer> testmap = new LinkedHashMap<Integer, Integer>();
testmap.put(0, 6);
testmap.put(1, 2);
int titi = NEvalLibNatives.test(testmap); |
l'exécution plante après la ligne "ici3"
j'ai tenté en rajoutant le static mais ça ne fonctionne pas:
si quelqu'un voit l'erreur je suis preneur!
merci d'avance
Partager