当我在启动后尝试运行该应用程序时,它在 logcat 中显示异常,如下所示:
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)
在类文件中调用执行方法后出现错误。
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时,它得到空值。
是否不推荐使用execute()方法,如果是,使用post方法执行http连接调用的解决方案是什么。
请为我提供一些针对此错误的建议。
提前感谢您的建议和答复!
上述解决方案对我不起作用。
useLibrary 'org.apache.http.legacy'
在 gradle 中添加这一行对我有用。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)