java List question

Hello there,

can somebody please explain this line of code.thanks

List<NameValuePair> params = new ArrayList<NameValuePair>();

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

zolfAuthor Commented:
what i am trying to do is

I have these two methods. i am using the executeHttpPost method in the login method to pass 2 parameter.but i get error in the login method when i try to add the String to the List.please help

public String executeHttpPost(List<NameValuePair> data)
			HttpClient client = getHttpClient();
			//String postURL = furl;
			/*Log.d("ZAJ sendPost URL", postURL + " " + data.get(0).toString() + " "
					+ data.get(1).toString());*/
			HttpPost post = new HttpPost(url);
			List<NameValuePair> params = new ArrayList<NameValuePair>();
			params.add(new BasicNameValuePair("username", data.get(0).toString()));
			params.add(new BasicNameValuePair("password", data.get(1).toString()));
			UrlEncodedFormEntity ent = new UrlEncodedFormEntity(params, HTTP.UTF_8);
			HttpResponse responsePOST = client.execute(post);
			HttpEntity resEntity = responsePOST.getEntity();
			if (resEntity != null)
				String response = EntityUtils.toString(resEntity);
				Log.i("RESPONSE", response);
				return response;

		catch (Exception e)
		return null;

Open in new window


public boolean login(String username,String password)
		 * Log.d("ZAJ URL", url + "?action=login&username=" +
		 * data.get(0).toString() + "&password=" + data.get(1).toString());

		//String fullURL = url + "?action=login";
		List<NameValuePair> data = new ArrayList<NameValuePair>();
		String response = executeHttpPost(data);

		String delimiter = "\\|";

		String[] temp = response.split(delimiter);

		if (temp[0].equals("100"))
			return true;
			return false;

Open in new window

Your list only accepts an instance of "NameValuePair". Is a string an instance of NameValuePair? No. So you can't put a string in it.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Tomas Helgi JohannssonDatabase Administrator / Software EngineerCommented:

What error do you get ?

    Tomas Helgi
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

This line means that:
The list stores objects of type NameValuePair class, so you can't add any other objects of another type.

Best wishes
try this,

data.add(new BasicNameValuePair("username", username));
data.add(new BasicNameValuePair("password", password));
Sathish David Kumar NArchitectCommented:
if your using apache http client then you can use name NameValuePair. thats is using messaging purpose .

 ksivananth mentioned correct solution for that
zolfAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.