java.lang.NoSuchMethodError: 没有为 HttpClientResponse 执行虚拟方法 [英] java.lang.NoSuchMethodError: No virtual method execute for HttpClientResponse

查看:36
本文介绍了java.lang.NoSuchMethodError: 没有为 HttpClientResponse 执行虚拟方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在启动后尝试运行应用程序时,它在 logcat 中显示异常,如下所示:

When I try to run the app after launching it is showing exception in logcat like this:

java.lang.NoSuchMethodError: No virtual method execute(Lorg/apache/http/client/methods/HttpUriRequest;)
Lorg/apache/http/client/methods/CloseableHttpResponse; 
in class Lorg/apache/http/impl/client/DefaultHttpClient;
or its super classes (declaration of 'org.apache.http.impl.client.DefaultHttpClient' appears in /system/framework/ext.jar)

在类文件中调用execute方法后出错.

In class file is getting error after calling execute method.

CloseableHttpResponse httpResponse = null;

httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(strServiceURL);
//When executing the below line get null value for response.
httpResponse = httpClient.execute(httpGet);  
httpEntity = httpResponse.getEntity();
responsePayload = EntityUtils.toString(httpEntity);

在尝试调用 execute() 方法时,当我更改为 HttpResponse 并添加 http-client-4.3.5.jar 时,它获取空值.

While trying to call execute() method it's getting null value when I change to HttpResponse and by adding http-client-4.3.5.jar.

execute() 方法是否已弃用,如果是,使用 post 方法执行 http 连接调用的解决方案是什么.

Whether execute() method is deprecated if so what is the solution to execute the http connection call using post method.

请为我提供一些针对此错误的建议.提前感谢您的建议和解答!

Please provide me some suggestions for this error. Thanks for suggestions and answers in advance!

推荐答案

上述解决方案对我不起作用.

Above solutions did not work for me.

useLibrary 'org.apache.http.legacy'

在 gradle 中添加这一行对我有用.

Adding this line in gradle worked for me.

这篇关于java.lang.NoSuchMethodError: 没有为 HttpClientResponse 执行虚拟方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆