ArrayIndexOutOfBoundsException Error - Tried debugging but still no solution
in
Programming Questions
•
2 years ago
Hi, I've read up on the coding and also searched specifically for this error message. I've tried to debug but can't find the issue. Does anyone know what could be wrong with coding? FYI: Ive changed out URLs I'm using to keep it general.
This program is very simple. Its parses the first page for the first HREF it finds and then follows that link, opens up new page, does the same search for HREF and continues. The issue I'm having is making sure the HREF URL is not within parentheses but outside of them. but the error message is coming from somewhere else.
- String[] lines;
- String pTag = "<p>";
- String hrefTag = "<a href=\"";
- int count=0;
- int i = 0;
- String found;
- String rightHREF;
- String line;
- String[] m1;
- String[] m2;
- String[] checkPara;
- String[] checkPara2;
- String para = "\\(";
- String para2 = "\\)";
- String domain = "http://www.domain.com";
- String newHREF = "http://www.domain.com/specific_page";
-
- void setup() {
- search4URL(); // start searching
- }
-
- void search4URL() { // search url
- while(count<15) { // search this number of urls
- lines = loadStrings(newHREF); // Load new URL
- println(newHREF+", i = "+ i + ", found = " + found + ", Array Length = "+ lines.length); // Debug, print NEW URL
- //println(lines);
- while(found == null) { // do this until you find first URL in body
- m1 = match(lines[i], pTag); // check each line for <p> tag
- if (m1 != null) { // if found a line with <p> then check if it has a url
- //println("----in first tag loop"); // DEBUG
- line = lines[i]; // extract line to test further
- m2 = match(line, hrefTag); // check if line has url
- if (m2 != null) { // if found a url then test and do extraction
- while(rightHREF == null) { // Do this until you have extracted correct HREF
- int beginPos = line.indexOf(hrefTag); // Get position of first HREF location
- String textBefore = line.substring(0,beginPos); // Extract text before HREF
- String s = line.substring(beginPos+9);// Extract text after HREF text
- checkPara = match(textBefore, para); // Check if text before HREF has a "("
- checkPara2 = match(textBefore, para2); // Check if text before HREF has a ")"
- println("i = "+i+" , checkPara = "+checkPara+" , checkPara2 = "+ checkPara2);
- if (checkPara != null) { // if there is an opening parentheses before HREF then
- if (checkPara2 != null) { // and if there is a closing parentheses before HREF then link found is valid
- int endPos = s.indexOf("\""); // Get position of end of URL
- String href = s.substring(0,endPos); // Extract URL from text
- newHREF = (domain + href); // Update newHREF with new URL
- found = "1"; // Exit while (found) loop
- rightHREF = "1";
- } else { // Else then link found is within parentheses.
- line = (s);
- }
- } else {
- int endPos = s.indexOf("\""); // Get position of end of URL
- String href = s.substring(0,endPos); // Extract URL from text
- newHREF = (domain + href); // Update newHREF with new URL
- found = "1"; // Exit while (found) loop
- rightHREF = "1";
- }
- //println(newHREF);
- m1 = null; // Exit m1 loop
- m2 = null; // Exit m2 loop
- checkPara = null;
- checkPara2 = null;
- }
- } // End of URL found & Extraction loop
- } // End of TAG found & find URL loop
- i++; // Lets go to next line in page
- } // End of searching whole page
- i = 0; // reset line counter
- found = null; // reset FOUND indicator
- count++; // lets go to next URL
- }
- }
- http://www.domain.com/specific_page/), i = 0, found = null, Array Length = 100
- i = 61 , checkPara = null , checkPara2 = null
- http://www.domain.com/second_page, i = 0, found = null, Array Length = 110
- processing.app.debug.RunnerException: ArrayIndexOutOfBoundsException: 1080
- at processing.app.Sketch.placeException(Sketch.java:1543)
- at processing.app.debug.Runner.findException(Runner.java:583)
- at processing.app.debug.Runner.reportException(Runner.java:558)
- at processing.app.debug.Runner.exception(Runner.java:498)
- at processing.app.debug.EventThread.exceptionEvent(EventThread.java:367)
- at processing.app.debug.EventThread.handleEvent(EventThread.java:255)
- at processing.app.debug.EventThread.run(EventThread.java:89)
- Exception in thread "Animation Thread" java.lang.ArrayIndexOutOfBoundsException: 1080
- at wiki_philosophy.search4URL(wiki_philosophy.java:52)
- at wiki_philosophy.setup(wiki_philosophy.java:43)
- at processing.core.PApplet.handleDraw(PApplet.java:1583)
- at processing.core.PApplet.run(PApplet.java:1503)
- at java.lang.Thread.run(Thread.java:680)
Thanks in advance!
1