时间:2021-07-01 10:21:17 帮助过:22人阅读
代码:
List<Student> delByStudent(String priNum){
RealmResults<Student> studentsList = myStudentRealm.where(Student.class).equalTo("num",priNum).findAll();
for (int i = 0;i<studentsList.size();i++)
studentsList.deleteFirstFromRealm();
return studentsList;
在for的循环语句
studentsList.deleteFirstFromRealm();
报错:????
java.lang.IllegalStateException: Changing Realm data can only be done from inside a transaction.
myStudentRealm.beginTransaction();
// change data to realm
myStudentRealm.commitTransaction();
// delete student by primary key(StuNum)
List<Student> delByStudent(String priNum){
RealmResults<Student> studentsList = myStudentRealm.where(Student.class).equalTo("num",priNum).findAll();
myStudentRealm.beginTransaction();
for (int i = 0;i<studentsList.size();i++) {
studentsList.deleteLastFromRealm();
Log.e("stu","-------delet_by-------"+studentsList);
}
myStudentRealm.commitTransaction();
return studentsList;
realm数据库报错:Changing Realm data can only be done from inside a transaction.
标签:find state 解决方法 elb ast pre ima mys list