title: Index out of bounds exception in android
body: <p>I am getting the below error for the attached code. The issue here is that the thread is running even after exiting the "for" loop. All i am doing is that at the click of a button, i am uploading a bunch of files to cloud. <code>ListofDocs[]</code> is where i have stored my list of files that I want to upload. Any help is appreciated. TIA.</p>
  
  <pre><code>11-03 21:23:27.793: E/AndroidRuntime(24480): FATAL EXCEPTION: Thread-11897
  11-03 21:23:27.793: E/AndroidRuntime(24480): java.lang.ArrayIndexOutOfBoundsException: length=12; index=12
  11-03 21:23:27.793: E/AndroidRuntime(24480):    at com.projects.scloud.PicsList$1$1.run(PicsList.java:99)
  11-03 21:23:27.793: E/AndroidRuntime(24480):    at java.lang.Thread.run(Thread.java:856)
  </code></pre>
  
  
  
  <pre><code>for(i=0; i &lt; ListofDocs.length; i++) {
            Log.i("Value of i: ", String.valueOf(i));
          MessageText.setText("Upload Documents");
  
          /************* Php script path ****************/
          upLoadServerUri = "http://www.androidexample.com/media/UploadToServer.php";
          Backup.setOnClickListener(new OnClickListener() {            
              @Override
              public void onClick(View v) {
                  dialog = ProgressDialog.show(DocsList.this, "", "Uploading file...", true);
                  new Thread(new Runnable() {
                      public void run() {
                          runOnUiThread(new Runnable() {
                              public void run() {
                                  MessageText.setText("uploading started.....");
                              }
                          });                   
  
                          uploadFile(ListofDocs[i]);
                      }
                  }).start();
              }
          });
        }
  </code></pre>