title: How can i post data on a Website with android http client?
body: <p>I must make an android app, that can controll a playcar!
  I have a seekbar and with this can i controll how fast it is!
  And every time, it change the app should send the data on a website of a friend!
  My Problem is that, if i try to test the app, the app crashs! It shows no fails it simply crash! Here is the code:</p>
  
  <p>activity_main.xml:
  '''</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context=".MainActivity"&gt;
  
      &lt;SeekBar
          android:id="@+id/seekbar"
          style="@style/Widget.AppCompat.SeekBar.Discrete"
          android:layout_width="200dp"
          android:layout_height="50dp"
          android:layout_marginBottom="380dp"
          android:max="10"
          android:rotation="270"
          app:layout_constraintBottom_toBottomOf="parent"
          app:layout_constraintStart_toStartOf="parent" /&gt;
  
      &lt;TextView
          android:id="@+id/textseek"
          android:layout_width="100sp"
          android:layout_height="36sp"
          android:layout_marginStart="62sp"
          android:layout_marginLeft="62sp"
          android:layout_marginTop="120sp"
          android:text="@string/_1"
          android:textColor="#00FF00"
          android:textSize="30sp"
          android:textStyle="bold"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toTopOf="parent" /&gt;
  
      &lt;ImageButton
          android:id="@+id/imageButton1"
          android:layout_width="62dp"
          android:layout_height="57dp"
          android:layout_marginStart="62dp"
          android:layout_marginLeft="62dp"
          android:layout_marginBottom="163dp"
          android:contentDescription="@string/leftround"
          app:layout_constraintBottom_toBottomOf="parent"
          app:layout_constraintStart_toStartOf="parent"
          app:srcCompat="@drawable/left" /&gt;
  
      &lt;ImageButton
          android:id="@+id/imageButton2"
          android:layout_width="62dp"
          android:layout_height="57dp"
          android:layout_marginEnd="95dp"
          android:layout_marginRight="95dp"
          android:layout_marginBottom="163dp"
          android:contentDescription="@string/rightround"
          app:layout_constraintBottom_toBottomOf="parent"
          app:layout_constraintEnd_toEndOf="parent"
          app:srcCompat="@drawable/right" /&gt;
  
  
  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  '''
  '''
  MainActivity.java:
  
  ...
  package com.example.unwichtig;
  
  import androidx.appcompat.app.AppCompatActivity;
  
  import android.os.Bundle;
  import android.view.MotionEvent;
  import android.view.View;
  import android.widget.Button;
  import android.widget.ImageButton;
  import android.widget.SeekBar;
  import android.widget.TextView;
  import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.util.ArrayList;
  import java.util.List;
  
  import org.apache.http.HttpResponse;
  import org.apache.http.NameValuePair;
  import org.apache.http.client.ClientProtocolException;
  import org.apache.http.client.HttpClient;
  import org.apache.http.client.ResponseHandler;
  import org.apache.http.client.entity.UrlEncodedFormEntity;
  import org.apache.http.client.methods.HttpPost;
  import org.apache.http.impl.client.BasicResponseHandler;
  import org.apache.http.impl.client.DefaultHttpClient;
  import org.apache.http.message.BasicNameValuePair;
  
  import android.os.AsyncTask;
  import android.os.Bundle;
  import android.app.Activity;
  import android.util.Log;
  import android.view.Menu;
  import android.view.View;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.Toast;
  import android.annotation.SuppressLint;
  import android.net.wifi.WifiInfo;
  import android.net.wifi.WifiManager;
  import android.os.Bundle;
  import android.support.v4.app.RemoteActionCompatParcelizer;
  import android.view.View;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.TextView;
  import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.io.PrintWriter;
  import java.net.InetAddress;
  import java.net.ServerSocket;
  import java.net.Socket;
  import java.net.UnknownHostException;
  import java.nio.ByteBuffer;
  import java.nio.ByteOrder;
  
  public class MainActivity extends AppCompatActivity {
  
      public TextView text;
      public ImageButton left;
      public ImageButton right;
      public int prozess = 0;
      public int AppRichtungL;
      public int AppRichtungR;
  
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
  
  
          SeekBar sSeekBar = findViewById(R.id.seekbar);
          text = findViewById(R.id.textseek);
          left = (ImageButton) findViewById(R.id.imageButton1);
          right = (ImageButton) findViewById(R.id.imageButton2);
  
  sSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener(){
  
              @Override
              public void onProgressChanged(SeekBar sSeekBar, final int progress,
                                            boolean fromUser) {
                 // text.setText(String.valueOf(progress*51));
              prozess = Integer.valueOf((progress*51) - 255);
                 text.setText(String.valueOf(prozess));
  
                 //stellt je nach Stellung der SeekBar die Richtung ein
                  VorRueckwaerts();
  
  
                 left.setOnTouchListener(new View.OnTouchListener() {
                     @Override
                     public boolean onTouch(View v, MotionEvent event) {
                        switch(event.getAction()){
                            //Wenn Button gedrückt:
                            case MotionEvent.ACTION_DOWN: {
                                prozess = 51;
                                //Microcontroller();
                                //postData();
                                  break;
                            }
                            //Wenn Button losgelassen wird:
                            case MotionEvent.ACTION_UP: {
                                prozess = (progress*51)-255;
                                VorRueckwaerts();
                                  break;
                            }
  
                        }
                         return false;
                     }
  
                 });
                  right.setOnTouchListener(new View.OnTouchListener() {
                      @Override
                      public boolean onTouch(View v, MotionEvent event) {
                          switch(event.getAction()){
                              //Wenn Button gedrückt:
                              case MotionEvent.ACTION_DOWN: {
                                  //Microcontroller();
                                  //postData();
                                  prozess = 51;
                                  AppRichtungL = 0;
                                  AppRichtungR = 1;
                                  break;
                              }
                              //Wenn Button losgelassen wird:
                              case MotionEvent.ACTION_UP: {
                                prozess = (progress*51)-255;
                                  VorRueckwaerts();
                                  break;
                              }
  
                          }
                          return false;
                      }
  
                  });
  
              }
  
              @Override
              public void onStartTrackingTouch(SeekBar sSeekBar) {
              }
  
              @Override
              public void onStopTrackingTouch(SeekBar sSeekBar) {
              }
          });
  
      }
  
      public void VorRueckwaerts(){
          if(prozess &lt; 0)
          {
              AppRichtungL = 0;
              AppRichtungR = 0;
          }
  
          if(prozess &gt; 0)
          {
              AppRichtungL = 1;
              AppRichtungR = 1;
          }
          //Microcontroller();
          //postData();
          send();
      }
  
      public void send()
      {
          // get the message from the message text box
  
          // make sure the fields are not empty
          String msg = text.getText().toString();
  
              HttpClient httpclient = new DefaultHttpClient();
              HttpPost httppost = new HttpPost("https://schueler.bulme.at//~maximilian.rupp/spycar");
              try {
                  List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(2);
                  nameValuePairs.add(new BasicNameValuePair("id", "12345"));
                  nameValuePairs.add(new BasicNameValuePair("message", msg));
                  httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                  httpclient.execute(httppost);
  
              } catch (ClientProtocolException e) {
                  // TODO Auto-generated catch block
              } catch (IOException e) {
                  // TODO Auto-generated catch block
              }
  
  
      }
  }
  
  </code></pre>
  
  <p>'''</p>