我有这样的方法
jobject Profiling::getFullStatistic(JNIEnv *env)
{
env->PushLocalFrame(256); // fix for local references
jclass mapClass = env->FindClass("java/util/HashMap");
if (mapClass == nullptr)
{
return nullptr;
}
jmethodID init = env->GetMethodID(mapClass, "<init>", "(I)V");
jobject hashMap = env->NewObject(mapClass, init, m_values.size());
jmethodID put = env->GetMethodID(mapClass, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
for (auto &it: m_values)
{
env->CallObjectMethod(hashMap, put, env->NewStringUTF(it.first.c_str()), env->NewStringUTF(std::to_string(it.second).c_str()));
}
return env->PopLocalFrame(hashMap);
}
最后我得到了Map<String, String>,现在我想将此 Map 类型更改为Map<String, Integer>
所以,我只是将方法的签名更改put为此
jmethodID put = env->GetMethodID(mapClass, "put", "(Ljava/lang/Object;I;)Ljava/lang/Object;");
据我所知int签名是I...
而且我也改变了这一行
env->CallObjectMethod(hashMap, put, env->NewStringUTF(it.first.c_str()), it.second);
但是知道我有这样的错误
JNI DETECTED ERROR IN APPLICATION: JNI NewStringUTF called with pending
exception java.lang.NoSuchMethodError: no non-static method
"Ljava/util/HashMap;.put(Ljava/lang/Object;I;)Ljava/lang/Object;"
at java.util.Map com..ar.JniInterface.getProfilingStatistic(long)
(JniInterface.java:-2)
at void com..ar.ui.fragments.ar.ArScreen.lambda$testDeleteIt$1$ArScreen()
(ArScreen.java:156)
at void
com..ar.ui.fragments.ar.-$$Lambda$ArScreen$zqdXNYFzVzmF_ZYFKJRM26bZzUw.run()
(lambda:-1)
at void android.os.Handler.handleCallback(android.os.Message)
(Handler.java:873)
at void android.os.Handler.dispatchMessage(android.os.Message)
(Handler.java:99)
at void android.os.Looper.loop() (Looper.java:214)
at void android.app.ActivityThread.main(java.lang.String[])
(ActivityThread.java:6990)
at java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object,
java.lang.Object[]) (Method.java:-2)
at void com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run()
梵蒂冈之花
相关分类