gpt4 book ai didi

android - 没有 Lorg/apache/http/message/BasicHeaderValueFormatter 类型的静态字段 INSTANCE

转载 作者:行者123 更新时间:2023-12-02 16:23:53 26 4
gpt4 key购买 nike

我收到以下错误:

Process: com.project.publiko, PID: 27061
java.lang.NoSuchFieldError: No static field INSTANCE of type Lorg/apache/http/message/BasicHeaderValueFormatter; in class Lorg/apache/http/message/BasicHeaderValueFormatter; or its superclasses (declaration of 'org.apache.http.message.BasicHeaderValueFormatter' appears in /system/framework/ext.jar)
at org.apache.http.entity.ContentType.toString(ContentType.java:153)
at org.apache.http.entity.mime.MultipartFormEntity.<init>(MultipartFormEntity.java:56)
at org.apache.http.entity.mime.MultipartEntityBuilder.buildEntity(MultipartEntityBuilder.java:236)
at org.apache.http.entity.mime.MultipartEntity.getEntity(MultipartEntity.java:119)
at org.apache.http.entity.mime.MultipartEntity.writeTo(MultipartEntity.java:180)
at com.project.publiko.CustomMultipartRequest.getBody(CustomMultipartRequest.java:57)
at com.android.volley.toolbox.HurlStack.addBodyIfExists(HurlStack.java:236)
at com.android.volley.toolbox.HurlStack.setConnectionParametersForRequest(HurlStack.java:210)
at com.android.volley.toolbox.HurlStack.performRequest(HurlStack.java:106)
at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:93)
at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:110)

引用错误行(Gradle):

android {
useLibrary 'org.apache.http.legacy'
}
public class CustomMultipartRequest extends Request < String > {
private Response.Listener < String > mListener = null;
private Response.ErrorListener mEListener;

private long cacheTimeToLive = 0;
//
private Map < String,
String > header;
MultipartEntity entity;

@Override
public Map < String,
String > getHeaders() throws AuthFailureError {
// you can add your custom headers here
HashMap < String, String > headers = new HashMap < > ();

return headers;
}

public CustomMultipartRequest(String url, Response.ErrorListener eListener, Response.Listener < String > rListener, MultipartEntity entity) {
super(Method.POST, url, eListener);
mListener = rListener;
mEListener = eListener;
this.entity = entity;
}

@Override
public String getBodyContentType() {
return entity.getContentType().getValue();
}

@Override
public byte[] getBody() throws AuthFailureError {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try { **
Error Line ** entity.writeTo(bos);
String entityContentAsString = new String(bos.toByteArray());
Log.e("volley", entityContentAsString);
} catch (IOException e) {
VolleyLog.e("IOException writing to ByteArrayOutputStream");
}
return bos.toByteArray();
}

@Override
protected void deliverResponse(String response) {
Log.d("DEBUG::Volley", response.toString());
System.out.println("VolleyQueue: Response Delivered for " + getTag() +
" (" + getSequence() + ")");
mListener.onResponse(response);
// TODO Auto-generated method stub
}

@Override
protected Response < String > parseNetworkResponse(NetworkResponse response) {
// TODO Auto-generated method stub
try {

// Volley does not handle null properly, so implement null response
// check
if (response.data.length == 0) {
byte[] responseData = "{}".getBytes("UTF8");
response = new NetworkResponse(response.statusCode,
responseData, response.headers, response.notModified);
}

String jsonString = new String(response.data,
HttpHeaderParser.parseCharset(response.headers));
return Response.success(jsonString,
parseIgnoreCacheHeaders(response));
} catch (UnsupportedEncodingException e) {
System.out.println("VolleyQueue: Encoding Error for " + getTag() +
" (" + getSequence() + ")");
return Response.error(new ParseError(e));
}
}

public Cache.Entry parseIgnoreCacheHeaders(NetworkResponse response) {
long now = System.currentTimeMillis();

Map < String, String > headers = response.headers;
long serverDate = 0;
String serverEtag;
String headerValue;

headerValue = headers.get("Date");
if (headerValue != null) {
serverDate = HttpHeaderParser.parseDateAsEpoch(headerValue);
}
serverEtag = headers.get("ETag");

final long cacheHitButRefreshed = 15 * 60 * 1000; //Fifteen Minutes
final long cacheExpired = cacheTimeToLive;
final long softExpire = now + cacheHitButRefreshed;
final long ttl = now + cacheExpired;

Cache.Entry entry = new Cache.Entry();
entry.data = response.data;
entry.etag = serverEtag;
entry.softTtl = softExpire;
entry.ttl = ttl;
entry.serverDate = serverDate;
entry.responseHeaders = headers;

return entry;
}

@Override
public void deliverError(VolleyError error) {
super.deliverError(error);
}
}

调用类(class):

CustomMultipartRequest req = new CustomMultipartRequest(URL, //url where you want to send the multipart request
elistener, //instance of onErrorResponse Listener
rlistener, //instance of onResponse Listener
entityBuilder);
req.setShouldCache(false);
RequestQueue rq = Volley.newRequestQueue(context);
rq.add(req);

你能帮我解决这个错误吗?

提前致谢;)

最佳答案

是库版本错误尝试使用这个版本

 implementation 'org.apache.httpcomponents:httpclient:4.5.3'
api 'org.apache.httpcomponents:httpcore:4.4.6'
api 'org.apache.httpcomponents:httpmime:4.3.6'

关于android - 没有 Lorg/apache/http/message/BasicHeaderValueFormatter 类型的静态字段 INSTANCE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36946238/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com