mardi 3 mars 2015

If-statment didn't work correctly [duplicate]


This question already has an answer here:




i have some problems because i dont undestand why my checking with if didn't work.



List<Cards> myCardsList = dataBaseAdapter.getData();

int a = myCardsList.size();

for (int i = 0; i < a; i++) {


if (!myCardsList.get(i).getCardInBaseId().toString().equals("a")) {

if(myCardsList.get(i).getCardInBaseId().toString() == idTest){
Toast.makeText(getApplicationContext(),"Card already added" ,Toast.LENGTH_LONG).show();
}
}
}


i have List with some Strings like names, cardInBaseId etc, now i need to check in this array if this cardInBaseId = String idTEst. if cardInBaseId != idtest i need to do some code


P.S cardidInBase can be = "a" , or some number (i put it value a because if i try to do this method when cardInBaseId == null i have always NullPointedExeption


So help me pls and explain why my if didn't work correctly


Aucun commentaire:

Enregistrer un commentaire