Question

I would like to use NameValuePair that is part of Apache commons-lang (link). The problem is I am getting an error when trying to initialize NameValuePair object, like this:

NameValuePair pair = new NameValuePair()

or like this:

NameValuePair pair = new NameValuePair("name", "value").

Currently the only import that suggested for NameValuePair is org.apache.http.NameValuePair. So I downloaded commons-lang jar from the above link and added it to the libs folder in my project.

Still the only import option that is available is the one mentioned above.

Thanks for any help.

Was it helpful?

Solution

NameValuePair is a public interface, an abstract class.
You should use BasicNameValuePair to initialize a name value pair.

for example,

List<NameValuePair> pairs = new ArrayList<NameValuePair>();
pairs.add(new BasicNameValuePair("timestamp", timestamp));
pairs.add(new BasicNameValuePair("key", value));

OTHER TIPS

NameValuePair does not have the constructor. And this class is not included in Apache-commons jar.

Try to use BasicNameValuePair instead.

BasicNameValuePair pair = new BasicNameValuePair("name", "value");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top