android: 无法解析符号 "urls"
android: cannot resolve the symbol "urls"
我是 android 编程新手,我正在关注 youtube 视频中的代码,但我收到错误 "cannot resolve the symbol "urls"" for " HttpGet httppost = new HttpGet(urls[0 ]);"。我通过研究发现 android 中不再支持 HttpGet 是否有任何解决方法
@Override
protected Boolean doInBackground(String... params) {
try {
HttpGet httppost = new HttpGet(urls[0]);
HttpClient httpclient = new DefaultHttpClient();
HttpResponse respone = httpclient.execute(httppost);
int status = respone.getStatusLine().getStatusCode();
if (status == 200) {
HttpEntity entity = respone.getEntity();
String data = EntityUtils.toString(entity);
JSONObject jsono = new JSONObject(data);
JSONArray jarray = jsono.getJSONArray("forecast");
for (int i = 0; i < jarray.length(); i++) {
JSONObject object = jarray.getJSONObject(i);
Forecast forecast = new Forecast();
forecast.setCode(object.getString("code"));
forecast.setDate(object.getString("date"));
forecast.setDay(object.getString("day"));
forecast.setHigh(object.getString("high"));
forecast.setLow(object.getString("low"));
forecast.setText(object.getString("text"));
forecastList.add(forecast);
}
return true;
}
} catch (ParseException e1) {
e1.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return false;
}
如果您之前没有在代码中定义网址,只需将代码中的 url 替换为参数 。
您必须将 doInBackground 方法的参数名称更改为 url。您将其作为参数接收,这就是为什么它告诉未定义的网址。
@Override
protected Boolean doInBackground(String... urls) {
}
我是 android 编程新手,我正在关注 youtube 视频中的代码,但我收到错误 "cannot resolve the symbol "urls"" for " HttpGet httppost = new HttpGet(urls[0 ]);"。我通过研究发现 android 中不再支持 HttpGet 是否有任何解决方法
@Override
protected Boolean doInBackground(String... params) {
try {
HttpGet httppost = new HttpGet(urls[0]);
HttpClient httpclient = new DefaultHttpClient();
HttpResponse respone = httpclient.execute(httppost);
int status = respone.getStatusLine().getStatusCode();
if (status == 200) {
HttpEntity entity = respone.getEntity();
String data = EntityUtils.toString(entity);
JSONObject jsono = new JSONObject(data);
JSONArray jarray = jsono.getJSONArray("forecast");
for (int i = 0; i < jarray.length(); i++) {
JSONObject object = jarray.getJSONObject(i);
Forecast forecast = new Forecast();
forecast.setCode(object.getString("code"));
forecast.setDate(object.getString("date"));
forecast.setDay(object.getString("day"));
forecast.setHigh(object.getString("high"));
forecast.setLow(object.getString("low"));
forecast.setText(object.getString("text"));
forecastList.add(forecast);
}
return true;
}
} catch (ParseException e1) {
e1.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return false;
}
如果您之前没有在代码中定义网址,只需将代码中的 url 替换为参数 。
您必须将 doInBackground 方法的参数名称更改为 url。您将其作为参数接收,这就是为什么它告诉未定义的网址。
@Override
protected Boolean doInBackground(String... urls) {
}