title: App crashes when I press the button to connect to raspberry pi
body: <p>The app crashes when I press the button to connect to a raspberry pi. It prints "Checking Inventory" in the TextView, but crashes immediately after and ends the program on the pi, so I think the problem only has to do with the AsyncTask, but I'm not sure.</p>
  
  <p><strong>here is my code:</strong></p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      TextView results;
  
      public String response;
  
      private static final String TAG = "MainActivity";
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          results = findViewById(R.id.countTextView);
  
          Button thingBtn = findViewById(R.id.thingBtn);
  
  
          thingBtn.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  results.setText("Checking Inventory");
                  new ConnectTask().execute();
              }
          });
      }
  
      public String Authentication = "we gucci";
  
      public class ConnectTask extends AsyncTask&lt;String, Void, String&gt;{
          @Override
          protected void onPreExecute() {
              Log.d(TAG, "AsyncTask starting");
              super.onPreExecute();
          }
  
          @Override
          protected String doInBackground(String... message) {
              try {
                  Log.d(TAG, "Attempting to Connect to Socket");
                  InetAddress serverAddress = InetAddress.getByName("192.168.1.11"); //must change later!!!
                  Socket house = new Socket(serverAddress, 5060);
                  Log.d(TAG, "Connected to Socket on (" + serverAddress + ", " + house.getPort());
  
                  BufferedOutputStream bos =new BufferedOutputStream(house.getOutputStream());
                  bos.write(Authentication.getBytes("UTF-8"));
                  bos.flush();
  
                  BufferedReader serverResponse = new BufferedReader(new InputStreamReader(house.getInputStream()));
                  response = serverResponse.readLine();
                  Log.d(TAG, "Server response: " + response);
  
                  house.close();
                  Log.d(TAG, "socket closed");
  
              }catch (IOException e) {
                  System.exit(1);
              }
              return response;
          }
  
          @Override
          protected void onPostExecute(String response){
              Log.d(TAG, response);
              results.setText(response);   
          }
     }
  }
  </code></pre>
  
  <p>what could be the reason and how to solve this? </p>