1

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.

2
  • Have you added the jar file to project as a library in your IDE? Commented Oct 27, 2013 at 9:29
  • yes I did, I have added a built path to he jar, source and javadoc. Commented Oct 27, 2013 at 9:30

2 Answers 2

2

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)); 
Sign up to request clarification or add additional context in comments.

Comments

1

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"); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.