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.

Documentation's instructions generate Exception: "io.realm.exceptions.RealmException: Removing is not supported."

See original GitHub issue

I just started playing around with Realm on a small project I have. I want to be able to delete objects from the database. Your documentation states I should do the following:

// remove a single object
Dog dog = result.get(5);
dog.removeFromRealm();

This throws an exception instead of working:

    io.realm.exceptions.RealmException: Removing is not supported.
    at io.realm.RealmResults$RealmResultsIterator.remove(RealmResults.java:552)
    at java.util.AbstractCollection.remove(AbstractCollection.java:229)

And it is because the code always throws an exception at that point: https://github.com/realm/realm-java/blob/71e94e1ab8688bfb796e9f0e401462060428cd40/realm/src/main/java/io/realm/RealmResults.java#L552

What is the workaround here? Why hasn’t the documentation been updated?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
MobileOakcommented, Sep 22, 2015

I have tried again to get this working, to no avail.

I load from the database players for my app:

mPlayers = realm.where(Player.class).findAll();

This array is then passed to an ArrayAdapter class to be shown in a listview, with a button for deleting the player.

        mViewHolder.delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mListener != null) {
                    mListener.deletePlayer(player);
                }
            }
        });

This calls delete player on the original Activity. Originally I had this code:

public void deletePlayer(final Player player) {
    mPlayers.remove(player);
    mAdapter.notifyDataSetChanged();
    player.removeFromRealm();

I thought this would work as per the example in your documentation, but it doesn’t, it calls the “Removing is not supported” function and crashes my app.

So based on your suggestion, I thought I needed to do a new get() call on the original RealmResults and remove it that way, so I changed the code:

public void deletePlayer(final Player player) {
    mPlayers.remove(player);
    mAdapter.notifyDataSetChanged();

    for (int i = 0; i < mPlayers.size(); i++) {
      if (player == mPlayers.get(i)) {
        mPlayers.get(i).removeFromRealm();
      }
    }

This as well causes the Exception to be thrown.

This is your documentation:

// remove a single object
Dog dog = result.get(5);
dog.removeFromRealm();

There is no context here at all for me to figure out what result is, or how it was acquired. How is my code any different from what’s in your documentation? There’s no warning that the iterator version of the the removeFromRealm method will always throw an exception, nor how to avoid that. This is so far some of the worst documentation I’ve run into for an Android library, and if you expect people to use your product you should have better examples and documentation.

0reactions
multivoltagecommented, Sep 9, 2016

I tried some times, but I arrive at the same exception: I have a a list of TravelsRealms object:

for(TravelRealm t : travelRealms){
                    if(t.createdWhen == travel_key){
                        int index = travelRealms.indexOf(t);
                        realm.beginTransaction();
                        travelRealms.remove(index);
                        realm.commitTransaction();
                        homePagerAdapter.notifyDataSetChanged();
                        break;
                    }
}

I user “for” to search inside this list. when objcet is correct, I delete it with a simple remove. I tried with other method like remove(Object), or call t.deleteFromReam(). I have the same error every time

Read more comments on GitHub >

github_iconTop Results From Across the Web

Examples should be self-contained · Issue #1763 - GitHub
Documentation's instructions generate Exception : "io.realm.exceptions.RealmException: Removing is not supported." #1487.
Read more >
What happened to removing items from realm.io ...
io.realm.exceptions.RealmException: Removing object is not supported. Then I looked at the source code of RealmResults.java and I find this: ...
Read more >
How to Fix the Unsupported Operation Exception in Java
UnsupportedOperationException is a Java runtime exception that occurs when an unsupported operation is requested but could not be performed.
Read more >
Keychain returned unexpected status code - Realm - MongoDB
I install nuget Realm10.0.0.beta1 when code run on: var app = App.Create("realmmongoapp-ywehx"); I have this exception: Realms.Exceptions.
Read more >
Could not find the generated RealmProxy class: Annotation ...
... io.realm.exceptions.RealmException: Could not find the generated io.realm.IngradientRealmProxy class: Annotation processor may not have been executed.
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