Reputation: 143
I am using the following code to search through my Data Browser
. The columns are Location
and Weather
and the class is called Nowcast
.
If my Data Browser
has New York in it and the weather "sunny"
, the TextView showWeather
displays "The weather in New York is sunny".
However, if I search Los Angeles and it is not in the Data Browser
, it shows "The weather in Los Angeles is null"
whereas it should not enter the if
condition at all according to the code. What am I doing wrong?
public void getData(){
searchText = searchTextView.getText().toString();
ParseQuery<ParseObject> query = ParseQuery.getQuery("Nowcast");
query.whereEqualTo("Location", searchText);
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> object, ParseException e) {
if (e == null) {
for (ParseObject weatherObject : object) {
weatherData = weatherObject.getString("Weather");
}
showWeather.setText("The weather in " + searchTextToString + " is " + weatherData);
} else {
Toast.makeText(NowcastSearch.this, "No such location found",Toast.LENGTH_LONG).show();
}
}
});
}
Upvotes: 4
Views: 267
Reputation: 31438
whereas it should not enter the if condition at all according to the code
It shouldn't enter only if the ParseException
isn't null. In other words it shouldn't enter the if condition (the first branch of it) only if there's been a problem with your query (e.g. you passed the wrong type of argument for a field condition).
There's no problem with your query. So no exception has been thrown. The query in which not a single record matches your conditions can still be a valid query. The object
list is just empty but there hasn't been any errors with the whole process.
Upvotes: 1
Reputation: 3346
ParseException e
this exception is represeting if there is a problem while parsing whole data to objects. So you can check if parsing operation is successful or not by null checking it.
There was no exception parsing your data. That means you dont have corrupted datas or something another.
You are just getting null object because there is no data about it. You should null check your "weatherData".
Upvotes: 1