title: Caused by: java.lang.ArrayIndexOutofBoundsException: index=1
body: <p>I have been working on this application to download all the images from a webpage for about a day now, and after about 5 hours of google, no answers have turned up.  I keep getting the error message in the title along with the following logcat errors.</p>
  
  <pre><code>java.lang.RuntimeException: An error occured while executing doInBackground()
          at android.os.AsyncTask$3.done(AsyncTask.java:300)
          at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
          at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
          at java.util.concurrent.FutureTask.run(FutureTask.java:242)
          at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
          at java.lang.Thread.run(Thread.java:864)
   Caused by: java.lang.ArrayIndexOutOfBoundsException: index=1
          at java.util.regex.Matcher.appendEvaluated(Matcher.java:149)
          at java.util.regex.Matcher.appendReplacement(Matcher.java:111)
          at java.util.regex.Matcher.replaceAll(Matcher.java:321)
          at java.lang.String.replaceAll(String.java:1785)
          at com.luke.test.Download$Main.getImages(Download.java:117)
          at com.luke.test.Download$Main.doInBackground(Download.java:91)
          at com.luke.test.Download$Main.doInBackground(Download.java:74)
          at android.os.AsyncTask$2.call(AsyncTask.java:288)
          at java.util.concurrent.FutureTask.run(FutureTask.java:237)
  </code></pre>
  
  <p>Along with the errors I have provided, I have my code as well.</p>
  
  <pre><code>public class Download extends Activity {
      ProgressDialog mProgressDialog;
      EditText editText;
      Button button;
      String data;
      private String URL1;
      private ImageView downloadedImg;
      private ProgressDialog simpleWaitDialog;
      String stored = null;
      private String folderPath = android.os.Build.MODEL + "\\Internal storage\\Pictures\\Screenshots\\";
      private static final String name = ".jpg";
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_download);
          editText = (EditText) findViewById(R.id.editText1);
          button = (Button) findViewById(R.id.button1);
          button.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  data = editText.getText().toString();
                  URL1 = data;
                  Log.v("URL", URL1);
                  new Main().execute();
              }
          });
      }
  
      private class Main extends AsyncTask&lt;Void, Void, Void&gt; {
          public Void doInBackground(Void... params) {
  
              try {
  
  
                  Document doc = Jsoup.connect(URL1).get();
  
                  Elements img = doc.getElementsByTag("img");
  
                  for (Element el : img) {
  
  
                      String src = el.absUrl("src");
                      System.out.println("Image Found!");
                      System.out.println("src attribute is : " + src);
  
                      getImages(src, folderPath, name);
  
                  }
  
              } catch (IOException ex) {
                  System.err.println("There was an error");
                  Logger.getLogger(Download.class.getName()).log(Level.SEVERE, null, ex);
              }
  
              return null;
          }
  
          private void getImages(String src, String folderPath, String name) throws IOException {
  
              int indexname = src.lastIndexOf("/");
  
              if (indexname == src.length()) {
                  src = src.substring(1, indexname);
              }
  
              indexname = src.lastIndexOf("/");
              String srcname = src.substring(indexname, src.length());
              String Path = folderPath;
  
              String myString = Path + srcname + name;
              myString = myString.replace("?", "");
              myString = myString.replaceAll("/", "\\");
              System.out.println(myString);
  
              URL url = new URL(src);
              InputStream in = new BufferedInputStream(url.openStream());
              ByteArrayOutputStream out = new ByteArrayOutputStream();
              byte[] buf = new byte[1024];
              int n = 0;
              while (-1!=(n=in.read(buf)))
              {
                  out.write(buf, 0, n);
              }
              out.close();
              in.close();
              byte[] response = out.toByteArray();
              FileOutputStream fos = new FileOutputStream(myString);
              fos.write(response);
              fos.close();
          }
  
          protected void OnPostExecute(Void result) {
              mProgressDialog.dismiss();
          }
      }
  }
  </code></pre>
  
  <p>I know, it's very clunky and very over-populated with strings I am not currently using, which might be part of my problem.  So, with all that said, any help in figuring out this error would be much appreciated. </p>