1
Когда я звоню testInterface(), SetName() в порядке, но setChild() следующим образом:Android JNI почему setChild() в ParentClass IsNot доступны
E/AndroidRuntime(18708): java.lang.NoSuchMethodError: no non-static method "Lcom/***/TestParent;.setChild(Ljava/lang/Object;)V"
JNI
JNIEXPORT jobject JNICALL Java_***_testInterface(
JNIEnv * env, jobject thiz) {
jclass parent_cls = env->FindClass("com/wkn/muscle/activity/TestParent");
LOGD("testInterface 0");
jmethodID parent_mid = env->GetMethodID(parent_cls, "<init>", "()V");
LOGD("testInterface 1");
jobject parent_obj = env->NewObject(parent_cls, parent_mid);
LOGD("testInterface 2");
jstring str_parent = env->NewStringUTF("Parent_from_Native");
LOGD("testInterface 3");
jmethodID parent_set_name = env->GetMethodID(parent_cls, "setName",
"(Ljava/lang/String;)V");
LOGD("testInterface 4");
env->CallVoidMethod(parent_obj, parent_set_name, str_parent);
LOGD("testInterface 5");
jclass child_cls = env->FindClass("com/wkn/muscle/activity/TestChild");
LOGD("testInterface 6");
jmethodID child_mid = env->GetMethodID(child_cls, "<init>", "()V");
LOGD("testInterface 7");
jobject child_obj = env->NewObject(child_cls, child_mid);
LOGD("testInterface 8");
jstring str_child = env->NewStringUTF("Child_from_Native");
LOGD("testInterface 9");
jmethodID child_set_name = env->GetMethodID(child_cls, "setName",
"(Ljava/lang/String;)V");
LOGD("testInterface 10");
env->CallVoidMethod(child_obj, child_set_name, str_child);
LOGD("testInterface 11");
jmethodID parent_set_child = env->GetMethodID(parent_cls, "setChild",
"(Ljava/lang/Object;)V");
LOGD("testInterface 12");
env->CallVoidMethod(parent_obj, parent_set_child, child_obj);
LOGD("testInterface 13");
return parent_obj;
}
Java:
public class TestParent {
private TestChild child;
public TestParent(){
}
public String getName(){
return this.name;
}
public void setName(String name){
this.name = name;
}
public TestChild getChild(){
return this.child;
}
public void setChild(TestChild child){
this.child = child;
}
}
public class TestChild {
private String name;
public TestChild(){
}
public String getName(){
return this.name;
}
public void setName(String name){
this.name = name;
}
}