java List question

Hello there,

can somebody please explain this line of code.thanks

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

Open in new window


cheers
Zolf
zolfAsked:
Who is Participating?
 
basicinstinctConnect With a Mentor Commented:
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.
0
 
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)
	{
		try
		{
			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);
			post.setEntity(ent);
			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)
		{
			e.printStackTrace();
		}
		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>();
		
		data.add(username);
		data.add(password);
		
		
		String response = executeHttpPost(data);

		String delimiter = "\\|";

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

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

Open in new window

0
 
Tomas Helgi JohannssonCommented:
Hi!

What error do you get ?

Regards,
    Tomas Helgi
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
ElbasselConnect With a Mentor Commented:
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
0
 
ksivananthConnect With a Mentor Commented:
try this,

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

 ksivananth mentioned correct solution for that
0
 
zolfAuthor Commented:
thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.