Android - java.lang.ArrayIndexOutOfBoundsException
<p>I'm new to Java, but I have done some PSP coding in C before. This seems to be quite different.</p>

<p>Below is the stack trace for what I'm seeing:</p>

<pre><code>java.lang.RuntimeException: An error occured while executing doInBackground()
enter code hereenter code here`at android.os.AsyncTask$3.done(AsyncTask.java:299)
enter code here`at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.ArrayIndexOutOfBoundsException: length=1; index=1
at com.adev.abmp3.ViewSongDialog$FindLyrics.doInBackground(ViewSongDialog.java:173)
at com.adev.abmp3.ViewSongDialog$FindLyrics.doInBackground(ViewSongDialog.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
</code></pre>

<p>And here is the patch of code:</p>

<pre><code>@Override
protected Void doInBackground(Void... arg0) {
    String searchQuery = title.replaceAll("[^ \\w]", "");
    searchQuery = searchQuery.replace(" ", "+");
    String searchResult = httpRun("http://search.azlyrics.com/search.php?q="+searchQuery).toString();
    System.out.println("http://search.azlyrics.com/search.php?q="+searchQuery);
    if(!searchResult.contains("Sorry, no results") &amp;&amp; !searchResult.equals("")) {
        String link = searchResult.split("&lt;table width=100%&gt;")[1];
        link = link.substring(link.indexOf("&lt;a href=\""), link.indexOf("\" rel"));
        link = link.replace("&lt;a href=\"", "");

        String lR = httpRun(link).toString();
        if(lR != "" &amp;&amp; lR.contains("&lt;!-- start of lyrics --&gt;")) {
            lR = lR.substring(lR.indexOf("&lt;!-- start of lyrics --&gt;"), lR.indexOf("&lt;!-- end of lyrics --&gt;"));
            lR = lR.replace("&lt;!-- start of lyrics --&gt;", "");
            lyrics = lR;
        } else {
            fail = 1;
            lyrics = "Couldn't find lyrics";
        }
    } else {
        fail = 1;
        lyrics = "Couldn't find lyrics";
    }
    return null;
}
</code></pre>

<p>I've done some research, and have read that you can't print to the screen within <code>doInBackground</code> - but I'm not sure where to go from here. Any help would be appreciated.</p>

<p>EDIT: java.lang.StringIndexOutOfBoundsException
in java.lang.String.startEndAndLength</p>

<p>Heres the new stack:</p>

<pre><code>java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:299)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.StringIndexOutOfBoundsException: length=7338; regionStart=537; regionLength=-538
at java.lang.String.startEndAndLength(String.java:593)
at java.lang.String.substring(String.java:1474)
at com.adev.abmp3.ViewSongDialog$FindLyrics.doInBackground(ViewSongDialog.java:174)
at com.adev.abmp3.ViewSongDialog$FindLyrics.doInBackground(ViewSongDialog.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
</code></pre>
