Reputation: 3
I am trying to retrieve a string from parse and then i want to check whether that string is "Yes". The string is retrieved properly as i can see the string in the form of a toast, but in the very next line i am checking whether that string is equal to "Yes", and according to the data that i have set in my parse database it should execute the code of that if loop but it just doesn't. Here's the Code
ParseQuery<ParseObject> query = ParseQuery.getQuery("RequirementCheck");
query.getInBackground("TVQfYqeX3A", new GetCallback<ParseObject>() {
@Override
public void done(ParseObject parseObject, ParseException e) {
Toast t = Toast.makeText(getActivity(),parseObject.getString("Requirement") , Toast.LENGTH_LONG); //I get this toast of Yes
t.show();
if (parseObject.getString("Requirement") == "Yes") {
Toast t1 = Toast.makeText(getActivity(), "Work", Toast.LENGTH_LONG);
t1.show(); //This if code is not executed
}
else {
Toast t3 = Toast.makeText(getActivity(), "ERROR", Toast.LENGTH_LONG);
t3.show();
}
}
});
Upvotes: 0
Views: 62
Reputation: 3118
Do the following:
ParseQuery<ParseObject> query = ParseQuery.getQuery("RequirementCheck");
query.getInBackground("TVQfYqeX3A", new GetCallback<ParseObject>() {
@Override
public void done(ParseObject parseObject, ParseException e) {
Toast t = Toast.makeText(getActivity(),parseObject.getString("Requirement") , Toast.LENGTH_LONG); //I get this toast of Yes
t.show();
if (parseObject.getString("Requirement").equals("Yes")) {
Toast t1 = Toast.makeText(getActivity(), "Work", Toast.LENGTH_LONG);
t1.show(); //This if code is not executed
}
else {
Toast t3 = Toast.makeText(getActivity(), "ERROR", Toast.LENGTH_LONG);
t3.show();
}
}
});
Notice I replaced == with .equals(). For checking strings you must do .equals() rather than the == operation in Java
== checks if the two objects have the same reference. string.equals() checks if the contents of both string objects are the same. In this case, you are wanting the later of the two.
Upvotes: 1