當我安裝我的第一次應用在手機上的應用程序崩潰,因爲該領域的錯誤:This method is only available in managed mode
,我真的不明白,很多境界錯誤:此方法僅在管理模式下可用
這happends當我試圖讓班上的ListItem
排序列表Shoplist
public class Shoplist extends RealmObject implements Serializable {
private RealmList<ListItem> itemList; //ListItem extends `RealmObject`
@Ignore
private Realm realm;
@PrimaryKey
private long id;
public Shoplist() {
realm = Realm.getDefaultInstance();
}
public RealmList<ListItem> getItemList() {
return itemList;
}
public List<ListItem> getItems(String listOrder) {
RealmResults<ListItem> realmResults;
switch (listOrder) {
case PrefActivity.ASCENDING:
realmResults = getItemList().where().findAll(); // this crashes!
break;
case PrefActivity.DESCENDING:
realmResults = getItemList().where().findAllSorted(ListItem.TIME_STAMP, Sort.DESCENDING);
break;
}
return realmResults;
}
}
一個Shoplist對象是在一個叫做類像這樣創建RealmService
public Shoplist createShoplist(String title) {
realm = Realm.getDefaultInstance();
realm.beginTransaction();
Shoplist shoplist = new Shoplist(new RealmList<ListItem>(), title);
realm.copyToRealm(shoplist);
realm.commitTransaction();
return shoplist;
}
個
STATS:
境界搖籃插件:2.3.1
搖籃插件:2.2.3
編譯版本:25
的Android Studio版本:2.2.3
測試手機:三星Galaxy S7
這個【答案】(http://stackoverflow.com/questions/37162444/creating-managed-realmlist-outside-realmobject)可以幫助你與你的probelm –
這個答案可能會幫助你在你的問題 http://stackoverflow.com/questions/37162444/creating-managed-realmlist-outside-realmobject –
你真的應該關閉你的領域實例。此外,你真的不應該給你的模型類一個領域的實例。 –