【发布时间】:2012-03-15 23:38:24
【问题描述】:
我正在尝试访问服务器,以便接收 JSON 字符串。但显然在冰淇淋三明治中你不能在主线程中进行网络操作,但是 AsyncTask 类让我感到困惑并且无法正常工作。这是我目前所拥有的:
//up in main code
Void blah = null;
URI uri = "kubie.dyndns-home.com/R2Bar2/ingredients.php";
new DownloadFilesTask().execute(uri , blah, blah);
private class DownloadFilesTask extends AsyncTask<URI, Void, Void> {
protected Void doInBackground(URI... uri) {
HttpClient client = new DefaultHttpClient();
String json = "";
int duration = Toast.LENGTH_SHORT;
try {
HttpResponse response = null;
BufferedReader rd = null;
String line = "";
HttpGet request = new HttpGet(uri);
} catch (URISyntaxException e1) {
}
return null;
}
protected void onProgressUpdate(Integer... progress) {
}
protected void onPostExecute(Long result) {
}
它不喜欢我的HttpGet request = new HttpGet(uri)
它说将 uri 更改为 URI,但它已经是!
我尝试将所有参数更改为 Void,但我的应用程序只是强制关闭。
有人知道怎么做吗?
【问题讨论】:
标签: android networking android-asynctask android-4.0-ice-cream-sandwich http-get