如果您檢查link上的實現,則IOException是檢查的異常,並從代碼中拋出。 參考我從上面的鏈接更增加實現可以在註釋中找到實施
public List<Address> getFromLocationName(String locationName, int maxResults) throws IOException {
if (locationName == null) {
throw new IllegalArgumentException("locationName == null");
}
try {
List<Address> results = new ArrayList<Address>();
String ex = mService.getFromLocationName(locationName,
0, 0, 0, 0, maxResults, mParams, results);
if (ex != null) {
throw new IOException(ex);
} else {
return results;
}
} catch (RemoteException e) {
Log.e(TAG, "getFromLocationName: got RemoteException", e);
return null;
}
}
NetworkOnMainThreadException是一個未經檢查的異常,因爲它從Java文檔擴展RuntimeException的這個link可能會有幫助。 希望這回答你的問題。
如果'mGeo'是一個'Geocoder',那麼你在自己的過程中並不是自己做網絡I/O。 – CommonsWare