I parsed a html code in to a string, and then removed the unwanted parts at the start and end of the string, that was the easy part.
But take a look at this log output and then at the code.
- 01-31 06:19:13.486: D/HTML_inString part to remove->: <a href="/wedstrijd/1622160/psv---vitesse/">
- 01-31 06:19:13.486: D/Should still be the same->:<a href="/wedstrijd/1622160/psv---vitesse/">
- 01-31 06:19:13.606: E/AndroidRuntime: Caused by: java.lang.StringIndexOutOfBoundsException: length=4959; regionStart=848; regionLength=-605
- 01-31 06:50:28.805: E/AndroidRuntime: at com.kalder.android.FeyenoordActivity.onCreate(FeyenoordActivity.java:48)
Notice that both outputs are the same, still, it gives me a StringIndexOutOfBoundsException while the string to be removed is displayed correctly in the log...
Line 3 in the following syntax is line 48 in my java file.
Using java Syntax Highlighting
- while (HTML_inString.contains("<a href=\"/wedstrijd/")) {
- if (HTML_inString.contains("<a href=\"/wedstrijd/")) {
- Log.d("HTML_inString part to remove->","" + HTML_inString.substring(HTML_inString.indexOf("<a href=\"/wedstrijd/"),HTML_inString.indexOf("<span class=\"club-home\">"))); ///// This is line 48...
- String temp = HTML_inString.substring(HTML_inString.indexOf("<a href=\"/wedstrijd/"),HTML_inString.indexOf("<span class=\"club-home\">"));
- Log.d("Should still be the same->", temp);
- HTML_inString = HTML_inString.replace("" + temp, ""); // I tried both with "" + and without that.
- } else {
- break;
- }
- try {
- Thread.sleep(100);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
so frankly it gives an error although the string to replace (temp) is correct.

