项目中类报红,提示找不到该类。
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
报错:
错误: 程序包org.apache.http.impl.cookie不存在
import org.apache.http.impl.cookie.DateUtils;
错误: 程序包org.apache.http.client不存在
import org.apache.http.client.HttpClient;
错误: 程序包org.apache.http.client.methods不存在
import org.apache.http.client.methods.HttpDelete;
错误: 程序包org.apache.http.client.methods不存在
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
错误: 程序包org.apache.http.client.methods不存在
import org.apache.http.client.methods.HttpGet;
错误: 程序包org.apache.http.client.methods不存在
import org.apache.http.client.methods.HttpPost;
错误: 程序包org.apache.http.client.methods不存在
import org.apache.http.client.methods.HttpPut;
错误: 程序包org.apache.http.client.methods不存在
import org.apache.http.client.methods.HttpUriRequest;
错误: 找不到符号
protected final HttpClient mClient;
错误: 找不到符号
public HttpClientStack(HttpClient client) {
^
符号: 类 HttpClient
位置: 类 HttpClientStack
错误: 找不到符号
private static void addHeaders(HttpUriRequest httpRequest, Map<String, String> headers) {
^
符号: 类 HttpUriRequest
位置: 类 HttpClientStack
解决方法:
在项目build.gradle中
在buildToolsVersion下边
defaultConfig上边
添加如下代码
useLibrary 'org.apache.http.legacy'
书到用时方恨少,纸上得来终觉浅。欢迎指正。
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/115003.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...