title: Send string message to server using android app
body: <p>I tried this code but I'm getting bellow error</p>
  
  <p>when I clicked the button this message appears "unfortunately app has stopped" then it exit my application.</p>
  
  <pre><code>public class testInput extends Activity {   
  
      Button Setbutton;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          // TODO Auto-generated method stub
          super.onCreate(savedInstanceState);
  
          setContentView(R.layout.test_input_page);
  
          Setbutton=(Button)findViewById(R.id.setbtn);
  
  
  Setbutton.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View v) {
  
                  new Asynactivity1().execute("");
                  });     
      }
  </code></pre>
  
  <p>//This is my Asyn class</p>
  
  <pre><code>public class Asynactivity1 extends AsyncTask&lt;String, Void, String&gt; {
  
      @Override
      protected String doInBackground(String... params) {
      postData("data");
          return null;
  }
  </code></pre>
  
  <p>//This is my data Posting method</p>
  
  <pre><code>  public void postData(String toPost) {
              // Create a new HttpClient and Post Header
              HttpClient httpclient = new DefaultHttpClient();
              HttpPost httppost = new HttpPost("http://adastest.mysite.com/index.php");
  
              //This is the data to send
              String MyName = toPost; //any data to send
  
              try {
              // Add your data
              List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(1);
              nameValuePairs.add(new BasicNameValuePair("action", MyName));
  
              httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
  
              // Execute HTTP Post Request
  
              ResponseHandler&lt;String&gt; responseHandler = new BasicResponseHandler();
              String response = httpclient.execute(httppost, responseHandler);
  
              //This is the response from a php application
              String reverseString = response;
              Toast.makeText(this, "response" + reverseString, Toast.LENGTH_LONG).show();
  
              } catch (ClientProtocolException e) {
              Toast.makeText(this, "CPE response " + e.toString(), Toast.LENGTH_LONG).show();
              // TODO Auto-generated catch block
              } catch (IOException e) {
              Toast.makeText(this, "IOE response " + e.toString(), Toast.LENGTH_LONG).show();
              // TODO Auto-generated catch block
              }
  
              }
  </code></pre>
  
  <p><br>
  Please help me<br><br>
  Thank you</p>