Solved

java List question

Posted on 2012-04-07
7
522 Views
Last Modified: 2012-04-12
Hello there,

can somebody please explain this line of code.thanks

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

Open in new window


cheers
Zolf
0
Comment
Question by:zolf
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 

Author Comment

by:zolf
ID: 37820659
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
 
LVL 23

Accepted Solution

by:
basicinstinct earned 200 total points
ID: 37820780
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
 
LVL 25

Expert Comment

by:Tomas Helgi Johannsson
ID: 37821119
Hi!

What error do you get ?

Regards,
    Tomas Helgi
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 2

Assisted Solution

by:Elbassel
Elbassel earned 100 total points
ID: 37821216
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
 
LVL 26

Assisted Solution

by:ksivananth
ksivananth earned 100 total points
ID: 37822458
try this,

data.add(new BasicNameValuePair("username", username));
data.add(new BasicNameValuePair("password", password));
0
 
LVL 20

Assisted Solution

by:Sathish David Kumar N
Sathish David  Kumar N earned 100 total points
ID: 37836144
if your using apache http client then you can use name NameValuePair. thats is using messaging purpose .

 ksivananth mentioned correct solution for that
0
 

Author Closing Comment

by:zolf
ID: 37841084
thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Can anyone please tell me why i can not find ID  investorCoolGrid inside the jsp page? 1 26
Java string replace 11 76
String array comparison 4 57
Java 8 to Java 6 8 43
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question