I'm using the Google maps activity and the app crushes when I write gibberish and hit "search". However, it works perfectly with a real location. How can I prevent it from crashing?
My code:
public void onSearch(View view) {
String location = locationTS.getText().toString();
if (location != null || !location.equals("")) {
Geocoder geocoder = new Geocoder(this);
List<Address> addressList=null;
try {
addressList= geocoder.getFromLocationName(location, 1);
mMap.clear();
} catch (IOException e) {
e.printStackTrace();
}
Address address=addressList.get(0);
LatLng latLng=new LatLng(address.getLatitude(),address.getLongitude());
mMap.addMarker(new MarkerOptions().position(latLng).title("Marker"));
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng,80));
latitudeB=latLng.latitude;
longitudeB=latLng.longitude;
}
else {
Toast.makeText(getApplicationContext(), "please fill in an available location",
Toast.LENGTH_LONG).show();
}
}