use*_*874 4 c java java-native-interface native
public class Student
{
private People people;
private Result result;
private int amount;
}
Run Code Online (Sandbox Code Playgroud)
这是Java中类的示例; 在C中,我试图让"学生"中的"人",但我失败了.但是,我可以从"学生"获得int类型"金额".
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;
}
Run Code Online (Sandbox Code Playgroud)
我试图将"people"作为fieldName传递给方法,但它仍然会出现以下错误:"java.lang.NoSuchFieldError:people"
| 归档时间: |
|
| 查看次数: |
16799 次 |
| 最近记录: |