title: Android Index out of bounds
body: <p>I am trying to get the <strong>bold</strong> text next to the hour scheldule ( from <a href="http://golfnews.no/golfpaatv.php" rel="nofollow">http://golfnews.no/golfpaatv.php</a> )put it in a String array , then , show it on my device's screen. I've put the Internet Access permission , so that is not the problem.The application crashes on my device . Reason : index out of bounds . I don't understand where's the problem . My code is :</p>
  
  <pre><code>package com.work.webrequest;
  
  import java.io.IOException;
  
  import org.apache.http.HttpResponse;
  import org.apache.http.HttpStatus;
  import org.apache.http.client.HttpClient;
  import org.apache.http.client.methods.HttpPost;
  import org.apache.http.impl.client.DefaultHttpClient;
  import org.apache.http.util.EntityUtils;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.widget.TextView;
  
  public class WebRequest extends Activity {
  
  
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          String trax;
  
          String aux[] = new String[10];
  
          setContentView(R.layout.main);
          TextView txt = (TextView) findViewById(R.id.textView1);
          trax=getPage();
  
         aux= title (trax);
  
  
         txt.setText(" Here I will display every title!!!");
  
      }
      private String[] title (String trax)
      {
  
          String result[] = new String[10];
          int ok=1;
          int s1,s2;
          int i=0;
          while(ok==1)
          {
              System.out.println("INDEX = "+trax.indexOf("&lt;h2&gt;"));
              ok=0;
              if(trax.indexOf("&lt;h2&gt;")!=-1)
              {
  
  
              ok=1;
              s1 =trax.indexOf("&lt;h2&gt;");
              s2 = trax.indexOf("&lt;/h2&gt;");
              result[i] = trax.substring(s1+4,s2);
              i++;
              trax = trax.substring(trax.indexOf("&lt;/h2&gt;"));
  
              }
  
          }
           return result;
      }
  
      private String getPage() {
          String str = "***";
  
          try
          {
              HttpClient hc = new DefaultHttpClient();
              HttpPost post = new HttpPost("http://www.golfnews.no/feed.php?feed=1");
              HttpResponse rp = hc.execute(post);
  
              if(rp.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
              {
                  str = EntityUtils.toString(rp.getEntity());
              }
          }catch(IOException e){
              e.printStackTrace();
          }  
  
          return str;
      }
  
  
  }
  </code></pre>
  
  <p>The number of <code>&lt;h2&gt;</code> and <code>&lt;/h2&gt;</code> is below 10 . My application crashes at the 2nd iteration . I am a beginner in android , so I don't know much  . Could you give me a hint ? I would really appreciate it . Thank you !</p>
  
  <p><strong>PS : I know what Index Out of bounds means , I just don't know why I get the error here .</strong></p>