我正在尝试使用android工作室在goolge和一些开源的帮助下实现一个有用的旅行计划应用程序
我有没有gradle.build的android应用程序。当它试图运行它我得到错误。
Error:(20, 28) java: package org.apache.http.util does not exist
以下是出现错误的代码部分。
如何解决错误?
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.ByteArrayBuffer;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public static String queryUrl(String url) {
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(url);
HttpResponse response;
try {
response = httpclient.execute(httpget);
Log.i(TAG, "Url:" + url + "");
Log.i(TAG, "Status:[" + response.getStatusLine().toString() + "]");
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream instream = entity.getContent();
BufferedReader r = new BufferedReader(new InputStreamReader(instream));
StringBuilder total = new StringBuilder();
String line;
while ((line = r.readLine()) != null) {
total.append(line);
}
instream.close();
String result = total.toString();
return result;
}
} catch (ClientProtocolException e) {
Log.e(TAG, "There was a protocol based error", e);
} catch (Exception e) {
Log.e(TAG, "There was some error", e);
}
return null;
}
答案 0 :(得分:0)
请参阅以下答案HttpClient won't import in Android Studio
我不知道你的模块的build.gradle是怎么样的,但是我认为你的apache库有些错误。
另外,我不建议在新的Android应用程序中使用apache HTTP库。请查看OkHttp或Volley
我会在评论中发帖,但我还没有足够的声誉。