[問題] 請問從API抓回來的資料能再抓一次資料嗎
@Override
protected void onPostExecute(String message) {
super.onPostExecute(message);
items = new ArrayList<>();
JSONArray rows;
try {
json_read = new JSONObject(message);
gps = json_read.getJSONArray("rows");
for (int i = 0; i < gps.length(); i++) {
JSONObject row = gps.getJSONObject(i);
Map<String, Object> item = new HashMap<>();
String Url = "http://xxxx/getAddress.ashx?h=" +
row.getString("lat") + "," + row.getString("lng");
try {
HttpClient httpClient = new DefaultHttpClient();
HttpGet get = new HttpGet(Url);
HttpResponse response = httpClient.execute(get);
HttpEntity resEntity = response.getEntity();
//Address = EntityUtils.toString(resEntity);
item.put("address", EntityUtils.toString(resEntity));
} catch (Exception e) {
item.put("address", e.toString());
}
items.add(item);
}
} catch (JSONException e) {
e.printStackTrace();
}
會報android.os.NetworkOnMainThreadException
請問大概要怎麼解
謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 210.61.125.247 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/AndroidDev/M.1590746090.A.FAB.html
推
05/29 18:02,
4年前
, 1F
05/29 18:02, 1F
→
05/29 18:10,
4年前
, 2F
05/29 18:10, 2F
→
05/29 18:10,
4年前
, 3F
05/29 18:10, 3F
→
05/29 18:29,
4年前
, 4F
05/29 18:29, 4F
→
05/31 13:48,
4年前
, 5F
05/31 13:48, 5F
→
05/31 13:48,
4年前
, 6F
05/31 13:48, 6F
AndroidDev 近期熱門文章
PTT數位生活區 即時熱門文章