android - I can't understand why addresslist value is null -


edittext location_tf = (edittext) findviewbyid(r.id.mapsearchaddress); string location = location_tf.gettext().tostring(); //geocoder geocoder = new geocoder(context, locale.getdefault()); list<address> addresslist = null;  if (location != null || !location.equals("")) {     geocoder geocoder = new geocoder(context, locale.getdefault());     try {         addresslist = geocoder.getfromlocationname(location, 1);     }     catch (ioexception e) {         toast.maketext(mapsactivity.this, "addess not found", toast.length_short).show();     }      if (addresslist != null && addresslist.size() > 0) {         address address = addresslist.get(0);         latlng latlng = new latlng(address.getlatitude(), address.getlongitude());         mmap.addmarker(new markeroptions().position(latlng).title("marker"));         mmap.animatecamera(cameraupdatefactory.newlatlng(latlng));     }     else {         toast.maketext(mapsactivity.this, "can't find address", toast.length_short).show();     } } 

if location equals empty string "" location != null true , enter if statement

use if(location != null && !location.equals(""))instead


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -