I want to transfer a C++ map to Java and have no idea how to define the return parameter so the method works. I had no trouble with string or int as return parameters, but i can′t get map working.
My Java method looks like this:
private native Map<String,String> sayHello();
My C++ Code is:
#include <stdio.h>
#include "stdafx.h"
#include "jni.h"
#include "HelloJNI.h"
#include <utility>
#include <map>
#include <string.h>
#include <iostream>
using namespace std;
JNIEXPORT jobject JNICALL Java_HelloJNI_sayHello
(JNIEnv *, jobject)
{
map<string, string> mMap;
mMap["1"] = "Ladi";
mMap["2"] = "Dida";
return mMap;
}
And of course i get an error, telling me i have to convert mMap to jobject somehow. But i have no idea how to do this.
I hope its no double-post, i just found some questions dealing with transmitting lists.
Thanks in advance.
See Question&Answers more detail:os