Search code examples
androidrealm

Realm loosing value on loop


I'm having a bit of a worry here, maybe it's me but I seem to be unable to get a realm value inside of a loop, let me explain :

I have 2 realmobjects:

public class jPV extends RealmObject{
@PrimaryKey
private String NUMPV;
private String NOMPV;

public jPV(){}

public jPV(String NUMPV, String NOMPV){
    this.NUMPV = NUMPV;
    this.NOMPV = NOMPV;
}

public String getNUMPV() {
    return NUMPV;
}

public void setNUMPV(String NUMPV) {
    this.NUMPV = NUMPV;
}

public String getNOMPV() {
    return NOMPV;
}

@Override
public String toString() {
    return this.NOMPV;
}

public void setNOMPV(String NOMPV) {
    this.NOMPV = NOMPV;
}}

and

public class jFlashLine extends RealmObject{
@PrimaryKey
private int PRIMARYKEY;
private String ANNEE;
private String MOIS;
private String PV;
private Float CA_MOIS;
private Float CA_MOIS_OBJ;

public jFlashLine(){}

public jFlashLine(int PRIMARYKEY,String ANNEE,String MOIS,String PV,Float CA_MOIS, Float CA_MOIS_OBJ){
    this.PRIMARYKEY = PRIMARYKEY;
    this.ANNEE = ANNEE;
    this.MOIS = MOIS;
    this.PV = PV;
    this.CA_MOIS = CA_MOIS;
    this.CA_MOIS_OBJ = CA_MOIS_OBJ;
}

public int getPRIMARYKEY() {
    return PRIMARYKEY;
}

public void setPRIMARYKEY(int PRIMARYKEY) {
    this.PRIMARYKEY = PRIMARYKEY;
}

public String getANNEE() {
    return ANNEE;
}

public void setANNEE(String ANNEE) {
    this.ANNEE = ANNEE;
}

public String getMOIS() {
    return MOIS;
}

public void setMOIS(String MOIS) {
    this.MOIS = MOIS;
}

public String getPV() {
    return PV;
}

public void setPV(String PV) {
    this.PV = PV;
}

public Float getCA_MOIS() {
    return CA_MOIS;
}

public void setCA_MOIS(Float CA_MOIS) {
    this.CA_MOIS = CA_MOIS;
}

public Float getCA_MOIS_OBJ() {
    return CA_MOIS_OBJ;
}

public void setCA_MOIS_OBJ(Float CA_MOIS_OBJ) {
    this.CA_MOIS_OBJ = CA_MOIS_OBJ;
}}

and I am trying to get the jPV.NOMPV from each jFlashLine where jPV.NUMPV = jFlashLine.PV

so far so good I'm looping on distinct jFlashLine

val users : ArrayList<jPV?> = arrayListOf<jPV?>()
for(line in realm.where(jFlashLine::class.java).distinct("PV")){
    users.add(realm.where(jPV::class.java).equalTo("NUMPV",line.pv).findFirst())
}

The thing is the users Array get filled with null objects. if evaluate expression line.pv it returns me "211" and if I execute

realm.where(jPV::class.java).equalTo("NUMPV","211").findFirst()

it returns me "NAME LASTNAME" but

realm.where(jPV::class.java).equalTo("NUMPV",line.pv).findFirst()

returns null. I really can't figure why... is there anyone to help me?

sincerely, Benji


Solution

  • Ok, sorry everybody, nervermind, i'm an idiot... For information purpose i was looking for 2 hours et didn't question the data i was getting. turns out, my Webservices was sending me "211 " instead of "211"... my bad...