title: How to solve NameValuePair cannot be a String in Android
body: <p>I'm learning how to build android Apps, and I'm trying to insert values into my Database using Java and PHP. But NameValuePair is giving me multiple errors.</p>
  
  <p>I already imported the necessary files. What am I doing wrong?</p>
  
  <p>My PHP file:</p>
  
  <pre><code>$connect = mysqli_connect("localhost","root","","users");
  
  if(mysqli_connect_errno($connect))
  {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
  else
  {
      echo "success";
  }
  
  $username=$_REQUEST['username'];
  $password=$_REQUEST['password'];
  $result = mysql_query(" insert into users(username,password)   values('$username','$password')"  );
  if($result == 1)
  {
      // successfully inserted
      $response["success"] = 1;
      $response["message"] = "User created.";
  
      // echoing JSON response
      echo json_encode($response);
  }
  else
  {
      // failed to insert row
      $response["success"] = 0;
      $response["message"] = "Oops! An error occurred.";
  
      // echoing JSON response
      echo json_encode($response);
  
  }
  </code></pre>
  
  <p>Java XML:</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:paddingBottom="@dimen/activity_vertical_margin"
      android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      tools:context="com.example.registro.MainActivity" &gt;
  
      &lt;EditText
          android:id="@+id/editText2"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignLeft="@+id/editText1"
          android:layout_below="@+id/editText1"
          android:layout_marginTop="70dp"
          android:ems="10"
          android:text="Password"
           &gt;
  
      &lt;/EditText&gt;
  
      &lt;EditText
          android:id="@+id/editText1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:layout_marginLeft="18dp"
          android:layout_marginTop="18dp"
          android:ems="10"
          android:text="Username" /&gt;
  
      &lt;Button
          android:id="@+id/button1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignLeft="@+id/editText2"
          android:layout_below="@+id/editText2"
          android:layout_marginTop="40dp"
          android:text="Button"
          android:onClick="create"
           /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Main activity file</p>
  
  <pre><code>package com.example.registro;
  
  
  import org.apache.http.NameValuePair;
  import org.apache.http.client.HttpClient;
  import org.apache.http.client.methods.HttpGet;
  import org.apache.http.client.methods.HttpPost;
  import org.apache.http.impl.client.DefaultHttpClient;
  
  import java.util.ArrayList; 
  import android.support.v7.app.ActionBarActivity;
  import android.os.Bundle;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.View;
  import android.widget.EditText;
  
  public class MainActivity extends ActionBarActivity {
  
      private EditText usernameField,passwordField;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
            usernameField = (EditText)findViewById(R.id.editText1);
            passwordField = (EditText)findViewById(R.id.editText2);
      }
  
         public void create(){
                String username = usernameField.getText().toString();
                String password = passwordField.getText().toString();
  
                // TODO Auto-generated method stub
                  HttpClient client = new DefaultHttpClient();
                  HttpPost httppost = new HttpPost("http://localhost/example/insert.php");
  
                  try
                  {
                      nameValuePairs = new ArrayList&lt;NameValuePair&gt;();
                      nameValuePairs.add(new BasicNameValuePair("username", username));
                      nameValuePairs.add(new BasicNameValuePair("password", password));
  
                      httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                      response = httpclient.execute(httppost);
                  }
                  catch(Exception e)
                  {
                      e.printStackTrace();
                  }
              }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.main, menu);
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          // Handle action bar item clicks here. The action bar will
          // automatically handle clicks on the Home/Up button, so long
          // as you specify a parent activity in AndroidManifest.xml.
          int id = item.getItemId();
          if (id == R.id.action_settings) {
              return true;
          }
          return super.onOptionsItemSelected(item);
      }
  
  
      }
  </code></pre>