我试图在 JNI/NDK 和 android 中实现回调。但是我无法获得方法签名或正确的东西,为什么找不到方法?
我的 MainActivity 实例调用 ndk 函数:
void populate(JNIEnv* aEnv, jobject aObj, jstring str){
....
jclass cls = aEnv->FindClass("com/example/jsonpoco/MainActivity");
jmethodID mid = aEnv->GetMethodID(cls, "add", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;D;D)V");
std::list<MyRefComplexType>::iterator it = ref->myRefs.begin();
for(int i = 0; i < ref->myRefs.size()/100;i++){
std::advance(it, 1);
printf(it->getMyNo().c_str()); //<-Works
jstring myNo = aEnv->NewStringUTF(it->getMyNo().c_str());
jstring myName = aEnv->NewStringUTF(it->getMyName().c_str());
jstring myUrl = aEnv->NewStringUTF(it->getMyUrl().c_str());
aEnv->CallVoidMethod(aObj,mid, myNo, myName, myUrl, it->getMyLocation()->getLatitude(), it->getMyLocation()->getLongitude());
}
我调用 Native 代码的 Java 类实现了以下处理回调的方法:
public void add(String myNo, String myName,String myUrl, double lat, double lon){
storesWrapper.add(storeNo, storeName, storeUrl, lat, lon);
}
我收到以下错误:
04-09 16:31:42.431: W/dalvikvm(25852): JNI WARNING: JNI method called with exception pending
04-09 16:31:42.431: W/dalvikvm(25852): in Lcom/example/jsonpoco/MainActivity;.json_parse:(Ljava/lang/String;)V (NewStringUTF)
04-09 16:31:42.431: W/dalvikvm(25852): Pending exception is:
04-09 16:31:42.431: I/dalvikvm(25852): java.lang.NoSuchMethodError: no method with name='add' signature='(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;D;D)V' in class Lcom/example/jsonpoco/MainActivity;