public void run() { try { socket = new Socket(address, port); if (socket == null) { Log.e(Constants.TAG, "[CLIENT THREAD] Could not create socket!"); return; } BufferedReader bufferedReader = Utilities.getReader(socket); PrintWriter printWriter = Utilities.getWriter(socket); if (bufferedReader == null || printWriter == null) { Log.e(Constants.TAG, "[CLIENT THREAD] Buffered Reader / Print Writer are null!"); return; } printWriter.println(city); printWriter.flush(); printWriter.println(informationType); printWriter.flush(); String weatherInformation; while ((weatherInformation = bufferedReader.readLine()) != null) { final String finalizedWeateherInformation = weatherInformation; weatherForecastTextView.post(new Runnable() { @Override public void run() { weatherForecastTextView.setText(finalizedWeateherInformation); } }); } } catch (IOException ioException) { Log.e(Constants.TAG, "[CLIENT THREAD] An exception has occurred: " + ioException.getMessage()); if (Constants.DEBUG) { ioException.printStackTrace(); } } finally { if (socket != null) { try { socket.close(); } catch (IOException ioException) { Log.e(Constants.TAG, "[CLIENT THREAD] An exception has occurred: " + ioException.getMessage()); if (Constants.DEBUG) { ioException.printStackTrace(); } } } } }