android - java.lang.NoClassDefFoundError: org.apache.http.impl.conn.PoolingHttpClientConnectionManager -
i have create 1 demo based on mashape api call.but error.i tried lots of suggestion.but not solution.
java code:
public class mainactivity extends actionbaractivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); new callmashapeasync().execute(); } private class callmashapeasync extends asynctask<string, integer, httpresponse<jsonnode>> { protected httpresponse<jsonnode> doinbackground(string... msg) { httpresponse<jsonnode> request = null; try { request = unirest.get("https://indianpost.p.mashape.com/getoffices.php?pincode=394101") .header("x-mashape-key", "my api") .header("accept", "application/json") .asjson(); } catch (unirestexception e) { // todo auto-generated catch block e.printstacktrace(); } return request; } protected void onprogressupdate(integer...integers) { } protected void onpostexecute(httpresponse<jsonnode> response) { string answer = response.getbody().tostring(); textview txtview = (textview) findviewbyid(r.id.textview1); txtview.settext(answer); } } }
build.gradle
apply plugin: 'com.android.application' android { compilesdkversion 21 buildtoolsversion "22.0.1" defaultconfig { applicationid "com.example.hungama3.myapplication" minsdkversion 16 targetsdkversion 21 versioncode 1 versionname "1.0" } buildtypes { release { minifyenabled false proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile filetree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:22.0.0' compile files('libs/gson-2.2.4.jar') compile files('libs/httpclient-4.3-beta1.jar') compile files('libs/mashape-java-client-2.0.10.jar') compile files('libs/unirest-java-1.3.0.jar') compile files('libs/org.apache.commons.logging-1.1.1.jar') }
error:
java.lang.runtimeexception: error occured while executing doinbackground() @ android.os.asynctask$3.done(asynctask.java:300) @ java.util.concurrent.futuretask.finishcompletion(futuretask.java:355) @ java.util.concurrent.futuretask.setexception(futuretask.java:222) @ java.util.concurrent.futuretask.run(futuretask.java:242) @ android.os.asynctask$serialexecutor$1.run(asynctask.java:231) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1112) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:587) @ java.lang.thread.run(thread.java:841) caused by: java.lang.noclassdeffounderror: org.apache.http.impl.conn.poolinghttpclientconnectionmanager @ org.apache.http.impl.client.httpclientbuilder.build(httpclientbuilder.java:459) @ com.mashape.unirest.http.options.options.refresh(options.java:41) @ com.mashape.unirest.http.options.options.<clinit>(options.java:27) @ com.mashape.unirest.http.httpclienthelper.preparerequest(httpclienthelper.java:138) @ com.mashape.unirest.http.httpclienthelper.request(httpclienthelper.java:121) @ com.mashape.unirest.request.baserequest.asjson(baserequest.java:64) @ com.example.hungama3.myapplication.mainactivity$callmashapeasync.doinbackground(mainactivity.java:33) @ com.example.hungama3.myapplication.mainactivity$callmashapeasync.doinbackground(mainactivity.java:27) @ android.os.asynctask$2.call(asynctask.java:288) @ java.util.concurrent.futuretask.run(futuretask.java:237) at android.os.asynctask$serialexecutor$1.run(asynctask.java:231) at java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1112) at java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:587) at java.lang.thread.run(thread.java:841)
i tried lots of jar file http apache library not getting solution. if 1 have suggestion tell me.
error focus line 37 indicate "request" in try catch.
edit again:
after second thought, android's library contains httpclient (pre android 6.0), including yourself, creating conflict. try remove jar , try.
remove line
compile files('libs/httpclient-4.3-beta1.jar')
you may need remove well
compile files('libs/org.apache.commons.logging-1.1.1.jar')
Comments
Post a Comment