I am writing an application for example. The example uses a list to store pairs of values:

List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("name", name)); params.add(new BasicNameValuePair("price", price)); params.add(new BasicNameValuePair("description", description)); 

Android Studio swears at NameValuePair and highlights it. As I understand it, the library is used.

 import org.apache.http.NameValuePair; 

Which is also highlighted in my NameValuePair at the end. Is it possible that I have no such library in the project? If so, how to add it?

  • Do you really need NameValuePair ? Maybe just replace it with AbstractMap.SimpleEntry ? - Sergey Gornostaev
  • @SergeyGornostaev do not know, I just write the application by example. In the future, using it, send a Post-request to the server and get the answer: JSONObject json = jsonParser.makeHttpRequest (url_create_product, "POST", params); If there is no difference, then your option can be used - danilshik

1 answer 1

Yes, you need to connect the library, here is the link to the latest version https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient/4.5.5

Everything is there.

Jar - http://central.maven.org/maven2/org/apache/httpcomponents/httpclient/4.5.5/httpclient-4.5.5.jar

Maven -

 <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.5.5</version> </dependency> 

Gradle - compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.5'

  • I added the jar file to the libs folder. The build.gradle (Module: app) appeared in dependies line: implementation files ('libs / httpclient-4.5.5.jar'). How to use the library? List everything is also underlined in red - danilshik
  • @danilshik If you use gradle, then it is better not to download the jar, but to use the repositories for this in build.gradle you need to register: repositories { mavenCentral() } dependencies { compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.5' } - Andrey
  • does this in build.gradle (Module: app) need to be inserted or into (Project: ....) - danilshik
  • @danilshik Oh yeah, I forgot this android (I was wrong). In build.gradle (Module: app), type android { useLibrary 'org.apache.http.legacy' } and that's it. - Andrey