title: Android: AsyncTask and reading internet data
body: <p>I have written a code to download some data from internet. Than i wanted to put it into asyncTask. And after that downloading stopped working. It looks like it cant finish try{} part so skips to exeption.</p>
  
  <p>From main activity "Nekaj" i call loadData() class, which extends AsyncData. From there i call "oto" class inside try command. "oto" class is used to read stuff from internet and returns array of strings. This worked when i called oto class directly from "Nekaj"class. What did I do wrong with using AsyncTask?
  Here is the code:</p>
  
  <pre><code>    public class Nekaj extends Activity {
  
  TextView Tkolo, Tbroj1;
  String[] brojevi_varijabla;
  String privremena_varijabla = null;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      // TODO Auto-generated method stub
      super.onCreate(savedInstanceState);
      setContentView(R.layout.bez_provjere_739);
      Tkolo = (TextView) findViewById(R.id.Xkolo);
      Tbroj1 = (TextView) findViewById(R.id.Xbroj1);
  
      /*
       * try { privremena_varijabla = test.kolo_739();
       * Tkolo.setText(privremena_varijabla); } catch (Exception e) { // TODO
       * Auto-generated catch block e.printStackTrace(); }
       */
  
      new loadData().execute();
  }
  
  public class loadData extends AsyncTask&lt;String, Integer, String&gt; {
  
      @Override
      protected String doInBackground(String... arg0) {
          // TODO Auto-generated method stub
  
          Oto test = new Oto();
  
          try {
              brojevi_varijabla = test.brojevi_739();
              if (Integer.valueOf(brojevi_varijabla[0]) &gt; 10) {
                  Tbroj1.setText("" + brojevi_varijabla[0]);
              } else {
                  Tbroj1.setText(" " + brojevi_varijabla[0]);
              }
  
          } catch (Exception e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
  
          return null;
      }
  }
  
  public class Oto {
  
      public String[] brojevi_739() throws Exception {
  
          int i = 0;
          int uvjet = 0;
          int varijabla = 0;
          char[] znak = { '&gt;', '&lt;' };
          BufferedReader in = null;
          String data[] = null;
          String provjera = "date-info";
          int[] polje = new int[2];
  
          try {
              HttpClient klijent = new DefaultHttpClient();
              URI webstranica = new URI(
                      "https://www.aaa.bb");
              HttpGet zahtjev = new HttpGet();
              zahtjev.setURI(webstranica);
              HttpResponse odgovor = klijent.execute(zahtjev);
              in = new BufferedReader(new InputStreamReader(odgovor
                      .getEntity().getContent()));
              StringBuffer brojevi = new StringBuffer("");
              String brojevi_string = null;
              String neki_string = null;
              String red = "";
  
              in.skip(21000);
              while ((red = in.readLine()) != null) {
                  varijabla = red.indexOf(provjera);
  
                  if (varijabla != -1) {
  
                      // 1. KOLO
                      if (uvjet == 0) { // onda sadrži taj
                                          // substring
                                          // !!!!
                          red = in.readLine(); // sada string red sadrži ono
                                                  // što
                                                  // želim, još moram samo to
                                                  // izrezati!!
                          do {
                              if (i == 0) {
                                  varijabla = red.indexOf(znak[i]);
                              }
  
                              else {
                                  varijabla = red.indexOf(znak[i], polje[0]);
                              }
  
                              if (varijabla != -1) // ako taj znak postoji u
                                                      // stringu
                              {
                                  if (i == 0) {
                                      polje[i] = varijabla + 1;
                                  }
  
                                  else {
                                      polje[i] = varijabla;
                                  }
                                  i++;
                              }
  
                          } while (i &lt;= 1);
  
                          neki_string = red.substring(polje[0], polje[1]);
                          Tkolo.setText(neki_string);
  
                          provjera = "Dobitna kombinacija";
                          uvjet++;
                          continue;
                      }
  
  
                  }
              }
  
              in.close();
  
              brojevi_string = brojevi.toString();
  
              data = brojevi_string.split("\n");
  
              return data;
  
          } finally {
              if (in != null) {
                  try {
                      in.close();
                      return data;
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
              }
          }
      }
  
  
  }}
  </code></pre>