使用Geocoder时, 未处理类型IOException异常

代码:

locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
                Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
                double longitude = location.getLongitude();
                double latitude = location.getLatitude();
                Geocoder gcd = new Geocoder(context, Locale.getDefault());
                List<Address> addresses = **gcd.getFromLocation(latitude, longitude, 1);**

星号包括的那句代码出错了。谢谢

Geocoder gcd = new Geocoder(this, Locale.getDefault());
try {
List

addresses = gcd.getFromLocation(latitude, longitude,1);
} catch (IOException e) {
e.printStackTrace();
}

Geocoder中的函数声明:
public java.util.List getFromLocation(double latitude, double longitude, int maxResults) throws java.io.IOException

你只需用try catch就行了。