public class Student
{
private People people;
private Result result;
private int amount;
}
这是Java类的示例;在 C 中,我试图让“学生”中的“人”,但我失败了。但是,我可以从“学生”中获得整数类型“金额”。
jobject getObjectFromObject(JNIEnv *env, jobject obj, const char * fieldName)
{
jfieldID fid; /* store the field ID */
jobject i;
/* Get a reference to obj's class */
jclass cls = (*env)->GetObjectClass(env, obj);
/* Look for the instance field s in cls */
fid = (*env)->GetFieldID(env, cls, fieldName, "L");
if (fid == NULL)
{
return 0; /* failed to find the field */
}
/* Read the instance field s */
i = (*env)->GetObjectField(env, obj, fid);
return i;
}
我试图将“people”作为 fieldName 传递给该方法,但它仍然给出以下错误:“java.lang.NoSuchFieldError: people”