1

Estoy intentando hacer una consulta en realm. Tengo un array con los id que quiero y me da este error:

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

cuando hago la iguacion de RealmQuery a RealmResult, hago este igualacion ya que necesito RealmResult para el constructor del adapter.

Os dejo el codigo:

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¡¡¡
    }
1
  • Has revisando cuantos elementos tienes?
    – Jorgesys
    el 12 abr. 2018 a las 17:00

1 respuesta 1

2

Si tienes solo un elemento en partsIDInt se provocará el error que comentas:

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

Realiza esta validación:

...
...
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);
}
...
...

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.