Error in Realm: UnsupportedOperationException: Missing right-hand side of OR

1

I'm trying to make a query in realm. I have an array with the id that I want and I get this error:

 java.lang.UnsupportedOperationException: Missing right-hand side of OR

When I make the RealmQuery match to RealmResult, I make this match since I need RealmResult for the adapter constructor.

I leave the code:

private RealmQuery<Clothes> query;
private RealmResults<Clothes> clothes = null;



    query = realm.where(Clothes.class);

    if(listClothesIDString != null) {
        String[] partsID = listClothesIDString.split("-");
        Integer[] partsIDInt = new Integer[partsID.length];
        for (int i = 0; i < partsID.length; i++) {
            partsIDInt[i] = Integer.parseInt(partsID[i]);
        }

        for (Integer id : partsIDInt) {
            query = query.or().equalTo("id", id);
        }

        clothes = query.findAll(); // Aqui da el error¡¡¡
    }
    
asked by CMorillo 12.04.2018 в 18:31
source

1 answer

2

If you have only one element in partsIDInt the error you are commenting on will be caused:

  

java.lang.UnsupportedOperationException: Missing right-hand side of OR

Perform this validation:

...
...
int  i = 0;
for (int id : partsIDInt) {
    if (i++ > 0) {  //* mayor a un elemento se usa OR!
        query = query.or();
    }
    query = query.equalTo("id", id);
}
...
...
    
answered by 12.04.2018 / 19:04
source