title: Android Studio app show the error message to user
body: <p>guys I have a problem with implement error handling in my application. 
  I want to display the error message to the user of my application when the response code from rest is not 200. In other words: If the connection is wrong, I want to display the message, that the user have to check his internet connection and try again. If everything is fine I want to do everything as usual so load the content.</p>
  
  <p>I write something like this:</p>
  
  <pre><code>Toast errorToast = Toast.makeText(NewsActivity.this, "Error, pls chech your internet connection and try again!", Toast.LENGTH_SHORT);
  errorToast.show();
  </code></pre>
  
  <p>and this:</p>
  
  <pre><code>if(response.getStatusLine().getStatusCode() == 200){}
  </code></pre>
  
  <p>But i don't know If this is good code and where should I insert it. I will be very grateful for your help and advice.</p>
  
  <p>This is this code:</p>
  
  <pre class="lang-java prettyprint-override"><code>public class NewsActivity extends Activity {
  
  private static final String URL = "http://10.0.2.2:8083/rest/aktualnosci";
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_news);
  
      new FetchItems().execute();
  }
  
  private class FetchItems extends AsyncTask&lt;String, Void, JSONArray&gt; {
  
      protected JSONArray doInBackground(String... params) {
          HttpClient httpclient = new DefaultHttpClient();
          HttpGet httpget = new HttpGet(URL);
          httpget.setHeader("Content-type", "application/json");
  
          JSONArray json = new JSONArray();
  
          try {
              HttpResponse response = httpclient.execute(httpget);
                  json = new JSONArray(EntityUtils.toString(response.getEntity()));
                  return json;
              }
  
          } catch (Exception e) {
              Log.v("Błędne wczytanie", e.getMessage());
          }
  
          return json;
      }
  
      protected void onPostExecute(JSONArray result) {
          ListView lst = (ListView) findViewById(R.id.aktualnosci_list);
          ArrayList&lt;String&gt; listItems = new ArrayList&lt;String&gt;();
          String contentToEdit;
          String titleContainer;
          TextView newsHeaderTextView = null;
          for (int i = 0; i &lt; result.length(); i++) {
              try {
                  titleContainer = result.getJSONObject(i).getString("title").toString();
                  listItems.add(titleContainer);
                  contentToEdit=result.getJSONObject(i).getString("body").toString();
                  contentToEdit= Html.fromHtml(contentToEdit).toString();
                  listItems.add(contentToEdit);
  
              } catch (Exception e) {
                  Log.v("Błędne wczytanie1", e.getMessage());
              }
          }
  
          ArrayAdapter ad = new ArrayAdapter(NewsActivity.this, android.R.layout.simple_list_item_1, listItems);
          lst.setAdapter(ad);
      }
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.menu_main, menu);
      return true;
  }
  </code></pre>
  
  <p>}</p>