J'apprends Realm et Recyclerview. J'ai créé une application simple où vous pouvez simplement ajouter des éléments et les supprimer. Tout fonctionne bien jusqu'à ce que je commence à supprimer les éléments un par un. Au tout dernier élément, lorsque je clique sur supprimer, cela me donne une exception.
java.lang.IllegalStateException: Object is no longer managed by Realm. Has it been deleted?
Voici mon code
@Override
public void onDeleteClick(int position) {
mRealm.beginTransaction();
mResult.get(position).deleteFromRealm();
mRealm.commitTransaction();
adapter.notifyItemRemoved(position);
}
Voici la pile complète
java.lang.IllegalStateException: Object is no longer managed by Realm. Has it been deleted?
at io.realm.internal.InvalidRow.getStubException(InvalidRow.java:192)
at io.realm.internal.InvalidRow.getString(InvalidRow.java:88)
at io.realm.PersonsRealmProxy.realmGet$firstName(PersonsRealmProxy.java:67)
at techiespk.realmpractice.Persons.getFirstName(Persons.java:22)
at techiespk.realmpractice.MyListAdapter.onBindViewHolder(MyListAdapter.java:44)
at techiespk.realmpractice.MyListAdapter.onBindViewHolder(MyListAdapter.java:15)
at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:5471)
at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:5504)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4741)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4617)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1994)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1390)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1353)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:574)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3028)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2906)
at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3283)