I am making one application which is displays long lat off inserted address.
It works fine but the problem is only that, When I insert Wrong address name like “abc xyz” in textbox than it stop and displays error on imulator that “Unfortunately, Location has stopped.”
I can not understand this, because as i know try and catch can handle any exceptions. Is it true????
There is only one text box and editbox in my sample project this is code of button click.
here is a code …
try{
bt.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
try {
//List<Address> addresses = geocoder.getFromLocation(LATITUDE, LONGITUDE, 1);
add=et.getText().toString();
List<Address> addresses = geocoder.getFromLocationName(add, 1);
if(addresses != null) {
Address returnedAddress = addresses.get(0);
StringBuilder strReturnedAddress = new StringBuilder("\n");
for(int i=0; i<returnedAddress.getMaxAddressLineIndex(); i++) {
strReturnedAddress.append("Latitude="+addresses.get(0).getLatitude()).append("\n");
strReturnedAddress.append("Longitude="+addresses.get(0).getLongitude()).append("\n");
strReturnedAddress.append("Country="+addresses.get(0).getCountryName()).append("\n");
strReturnedAddress.append("State="+addresses.get(0).getAdminArea()).append("\n");
}
myAddress.setText(strReturnedAddress.toString());
}
else{
myAddress.setText("No Address returned!");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
myAddress.setText("Canont get Address!");
}
/*Intent intent=new Intent(Main.this, Horoscope.class);
intent.putExtra("extra", myAddress.getText().toString());
startActivity(intent);*/
}
});
}
catch (Exception e) {
// TODO: handle exception
myAddress.setText("Canont get Address!");
}
1 Answer