I am trying to determine whether the array of objects is empty after receiving data from an API call and storing it in the state variable city_name
.
cities = this.state.city_name;
console.warn(cities); //this returns an empty array []
cities === null ? console.log(cities) : ToastAndroid.showWithGravity('No Result Found',ToastAndroid.LONG)
However, I keep encountering the error
double java.lang.Double.doubleValue() on a null object
. I have also attempted using cities.length == 0
and (this.state.city_name).length == 0
, but they result in the same error.
Below is the data received from the API call:
city_name = [{"country_flag_url": "https://b.zmtcdn.com/images/countries/flags/country_216.png", "country_id": 216, "country_name": "United States", "discovery_enabled": 1, "has_go_out_tab": 0, "has_new_ad_format": 0, "id": 11282, "is_state": 0, "name": "Del Aire, CA", "should_experiment_with": 0, "state_code": "CA", "state_id": 73, "state_name": "California"}, {"country_flag_url": "https://b.zmtcdn.com/images/countries/flags/country_216.png", "country_id": 216, "country_name": "United States", "discovery_enabled": 0, "has_go_out_tab": 0, "has_new_ad_format": 0, "id": 4463, "is_state": 0, "name": "Del Norte, CO", "should_experiment_with": 0, "state_code": "CO", "state_id": 74, "state_name": "Colorado"}, {"country_flag_url": "https://b.zmtcdn.com/images/countries/flags/country_216.png", "country_id": 216, "country_name": "United States", "discovery_enabled": 0, "has_go_out_tab": 0, "has_new_ad_format": 0, "id": 9431, "is_state": 0, "name": "Del Rio, TX", "should_experiment_with": 0, "state_code": "TX", "state_id": 111, "state_name": "Texas"}]
I would appreciate any assistance with resolving this issue. Thank you.