Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何为我的领域对象设置标识符?_Java_Android_Realm - Fatal编程技术网

Java 如何为我的领域对象设置标识符?

Java 如何为我的领域对象设置标识符?,java,android,realm,Java,Android,Realm,如何为我的领域对象设置标识符..我需要在Android应用程序的第二个活动中使用它进行查询。谢谢 学校目标: public class School extends RealmObject { @Required private String SchoolID; private String SchoolName; private RealmList<Student> Students; getters/setters public RealmList<Student&

如何为我的领域对象设置标识符..我需要在Android应用程序的第二个活动中使用它进行查询。谢谢

学校目标:

public class School extends RealmObject {

@Required
private String SchoolID;
private String SchoolName;
private RealmList<Student> Students;


getters/setters

public RealmList<Student> getStudents() {
    return Students;
}

public void setStudents(RealmList<Student> students) {
    Students = students;
}

您可以使用
@PrimaryKey


你是说标识符是主键吗?我不确定…我需要用它从我的领域对象检索数据。它还与
@PrimaryKey私有字符串SchoolID相关
public class Student extends RealmObject{

@Required
private String StudentID;
private String StudentName;

getters/setters

}
public class Student extends RealmObject {

@PrimaryKey
private String StudentID;
private String StudentName;

// getters/setters

}