0
I have a string that currently only gets "ERROR" and I did an if for when she gave me this value ran some things, it turns out that the comparison always fails, even the strings being exactly the same, I always compared string this way, I do not understand why it is not working:
try {
String mensagem = response.body().getAsJsonObject().get("error").getAsJsonObject().get("msg").toString();
String status = response.body().getAsJsonObject().get("status").toString();
//Log.i(TAG, "onResponse: "+mensagem);
Log.i(TAG, "onResponse: "+status);
if(status.equals("ERROR")){
Toast.makeText(SplashScreen.this, mensagem, Toast.LENGTH_SHORT).show();
habilitarformgerarsenha(true);
}else{
Log.i(TAG, "onResponse: Status mensagem:" + status);
}
}catch (NullPointerException e){
Log.i(TAG, "onResponse: "+e);
}
LOG:
02-05 23:57:41.036 30711-30711/1.com.br.doup I/igr: onResponse: "ERROR"
02-05 23:57:41.036 30711-30711/1.com.br.doup I/igr: onResponse: Status mensagem:"ERROR"
Do not capture
NullPointerException
. Instead see which line you are accessing something null, and give resolution to that case.– Isac
@Isac pulled the Try catch, nothing’s changed
– Igor Oliveira
It is not supposed to change unless you specify the line where the problem actually is. Now it is supposed to show the error you gave in the log and its line
– Isac
No error, does not fall in catch, it always falls in Else, even though the condition is true
– Igor Oliveira
Log.i(TAG, mensagem + "," + status);
before theif
shows what ?– Isac
I/Igr: "Invalid user!" ,"ERROR"
– Igor Oliveira
But the status has
ERROR
or"ERROR"
?. Pay attention because quotation marks make a difference, and if that’s the case you’ll never gettrue
– Isac
Has quotes yes it looks like "ERROR" is a string
– Igor Oliveira
Yes apparently his
String
already have quotes inside. You can easily test by changing yourif
forif(status.equals("\"ERROR\"")){
– Isac
@Isac was this very thing, put as answer, if possible how to remove the inside quotes
– Igor Oliveira