I’m trying to call a Java method from my native code, but it fails. I cannot call the method with a const string (i.e. “string” as a parameter nor by the following way.
If I remove the char[] parameter from the method and call it from the native only with the int parameter it’s work. So the problem is the char[] parameter.
I have the Java class Stats:
public class Stats {
HashMap<String, Integer> mStats;
public Stats() {
mStats = new HashMap<String, Integer>();
}
public void put(char[] key, int value) {
mStats.put(new String(key), value);
}
}
And a native function
void Java_com_..._testObject(JNIEnv* env, jobject javaThis,
jobject jStatsObj) {
jclass jstatistics_class = env->GetObjectClass(jStatsObj);
jmethodID jput_method = env->GetMethodID(jstatistics_class, "put", "(C[I)V");
char s[]={"hello"};
env->CallIntMethod(jStatsObj, jput_method, s, 3);
}
You have the method signature wrong.
(C[I)Vmeansvoid method(char, int[])You need
([CI)V.Source: this page.