question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

java.lang.IllegalArgumentException: Object not managed by Realm, so it cannot be removed

See original GitHub issue

I’m trying to delete Object from realm, but first time, I try to delete it, the application crashes, but then I reopen the application and try to delete, it is deleted. (doing this is recycler view)

realm.executeTransaction(new Realm.Transaction() {
                    @Override
                    public void execute(Realm realm) {

                        NotesPOJO note = notes.get(key);
                        note.deleteFromRealm();   //this is the line which shows the error


                    }
                });

For second attempt for item of recycler view, its deleting but for the first attempt the application is crashing.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
Zhuindencommented, Sep 24, 2017

java.lang.IllegalArgumentException: Object not managed by Realm, so it cannot be removed

That’s simple, it’s because notes is some kind of map, not a RealmResults or anything, and the NotesPOJO you’re storing inside it is not a managed RealmObject (was not obtained by querying Realm).

To delete an object from the Realm, the object you call deleteFromRealm() on has to be managed, aka it must be obtained from a RealmResults.

For second attempt for item of recycler view, its deleting

nah that just means you probably never stored it in the Realm.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Realm Exception 'value' is not a valid managed object
Solution 1 - Pass the unique identifer, then query the realm object: int uniqueId = Parcels.unwrap(data.getParcelableExtra("uniqueId"));.
Read more >
io.realm.RealmObject.isValid java code examples - Tabnine
Checks if the RealmObject is still valid to use i.e. the RealmObject hasn't been deleted nor has the io.realm.Realm been closed. It will...
Read more >
RealmObject (Realm 3.5.0) - MongoDB
Managed objects are thread confined so that they cannot be accessed from other threads than the one that created them. If this method...
Read more >
Create reactive mobile apps in a fraction of the time - Realm
public class Person extends RealmObject { @Required // Name is not ... object is managed by Realm, so any further changes to the...
Read more >
Fix list for IBM WebSphere Application Server V8.5
IT31238, MQ classes for Java application cannot get NameValueData from RFH2 when ... PH40532, OIDC TAI might not remove OAuth access token cache...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found