What am I doing differently in the first part, i.e., chapterTexts.get(0)) that I'm not doing in the second (i.e. chapterTexts.get(1)) ?
Here's all the parts that could be effecting it:
chapterScanners = new Scanner[19]; try { chapterScanners[0] = new Scanner(new File("./s3c1.txt")); } catch(FileNotFoundException fnfe) { System.out.println("Not found."); } try { chapterScanners[1] = new Scanner(new File("./s3c2.txt")); } catch(FileNotFoundException fnfe) { System.out.println("Not found."); } //selectPictures = new JMenu("Select Pictures"); chapterTexts = new ArrayList<ArrayList<String>>(); chapterTexts.add(new ArrayList<String>()); chapterTexts.add(new ArrayList<String>()); Scanner lineScanner = null; while(chapterScanners[0].hasNext()) { //System.out.println(chapterScanners[0].next()); String temp = chapterScanners[0].next(); if (temp.equals("<Page1>")) { String var = ""; while (chapterScanners[0].hasNext() && !chapterScanners[0].nextLine().equals("</Page1>")) { String nextInputLine = chapterScanners[0].nextLine(); lineScanner = new Scanner(nextInputLine); while(lineScanner.hasNext()) { var = var + lineScanner.nextLine(); } var = var + "\n" + "\n"; } chapterTexts.get(0).add(var); } else if (temp.equals("<Page2>")) { String var = ""; while (chapterScanners[0].hasNext() && !chapterScanners[0].nextLine().equals("</Page2>")) { String nextInputLine = chapterScanners[0].nextLine(); lineScanner = new Scanner(nextInputLine); while(lineScanner.hasNext()) { var = var + lineScanner.nextLine(); } var = var + "\n" + "\n"; } chapterTexts.get(0).add(var); } else if (temp.equals("<Page3>")) { String var = ""; while (chapterScanners[0].hasNext() && !chapterScanners[0].nextLine().equals("</Page3>")) { String nextInputLine = chapterScanners[0].nextLine(); lineScanner = new Scanner(nextInputLine); while(lineScanner.hasNext()) { var = var + lineScanner.nextLine(); } var = var + "\n" + "\n"; } chapterTexts.get(0).add(var); } else if (temp.equals("<Page4>")) { String var = ""; while (chapterScanners[0].hasNext() && !chapterScanners[0].nextLine().equals("</Page4>")) { String nextInputLine = chapterScanners[0].nextLine(); lineScanner = new Scanner(nextInputLine); while(lineScanner.hasNext()) { var = var + lineScanner.nextLine(); } var = var + "\n" + "\n"; } chapterTexts.get(0).add(var); } else if (temp.equals("<Page5>")) { String var = ""; while (chapterScanners[0].hasNext() && !chapterScanners[0].nextLine().equals("</Page5>")) { String nextInputLine = chapterScanners[0].nextLine(); lineScanner = new Scanner(nextInputLine); while(lineScanner.hasNext()) { var = var + lineScanner.nextLine(); } var = var + "\n" + "\n"; } chapterTexts.get(0).add(var); } else if (temp.equals("<Page6>")) { String var = ""; while (chapterScanners[0].hasNext() && !chapterScanners[0].nextLine().equals("</Page6>")) { String nextInputLine = chapterScanners[0].nextLine(); lineScanner = new Scanner(nextInputLine); while(lineScanner.hasNext()) { var = var + lineScanner.nextLine(); } var = var + "\n" + "\n"; } chapterTexts.get(0).add(var); } else if (temp.equals("<Page7>")) { String var = ""; while (chapterScanners[0].hasNext() && !chapterScanners[0].nextLine().equals("</Page7>")) { String nextInputLine = chapterScanners[0].nextLine(); lineScanner = new Scanner(nextInputLine); while(lineScanner.hasNext()) { var = var + lineScanner.nextLine(); } var = var + "\n" + "\n"; } chapterTexts.get(0).add(var); } else if (temp.equals("<Page8>")) { String var = ""; while (chapterScanners[0].hasNext() && !chapterScanners[0].nextLine().equals("</Page8>")) { String nextInputLine = chapterScanners[0].nextLine(); lineScanner = new Scanner(nextInputLine); while(lineScanner.hasNext()) { var = var + lineScanner.nextLine(); } var = var + "\n" + "\n"; } chapterTexts.get(0).add(var); } else if (temp.equals("<Page9>")) { String var = ""; while (chapterScanners[0].hasNext() && !chapterScanners[0].nextLine().equals("</Page9>")) { String nextInputLine = chapterScanners[0].nextLine(); lineScanner = new Scanner(nextInputLine); while(lineScanner.hasNext()) { var = var + lineScanner.nextLine(); } var = var + "\n" + "\n"; } chapterTexts.get(0).add(var); } } System.out.println("Size: " + chapterTexts.get(0).size()); lineScanner = null; while(chapterScanners[1].hasNext()) { //System.out.println(chapterScanners[1].next()); String temp = chapterScanners[1].next(); if (temp.equals("<Page1>")) { String var = ""; while (chapterScanners[1].hasNext() && !chapterScanners[1].nextLine().equals("</Page1>")) { String nextInputLine = chapterScanners[1].nextLine(); lineScanner = new Scanner(nextInputLine); while(lineScanner.hasNext()) { var = var + lineScanner.nextLine(); } var = var + "\n" + "\n"; } chapterTexts.get(1).add(var); } else if (temp.equals("<Page2>")) { String var = ""; while (chapterScanners[1].hasNext() && !chapterScanners[1].nextLine().equals("</Page2>")) { String nextInputLine = chapterScanners[1].nextLine(); lineScanner = new Scanner(nextInputLine); while(lineScanner.hasNext()) { var = var + lineScanner.nextLine(); } var = var + "\n" + "\n"; } chapterTexts.get(1).add(var); } else if (temp.equals("<Page3>")) { String var = ""; while (chapterScanners[1].hasNext() && !chapterScanners[1].nextLine().equals("</Page3>")) { String nextInputLine = chapterScanners[1].nextLine(); lineScanner = new Scanner(nextInputLine); while(lineScanner.hasNext()) { var = var + lineScanner.nextLine(); } var = var + "\n" + "\n"; } chapterTexts.get(1).add(var); } else if (temp.equals("<Page4>")) { String var = ""; while (chapterScanners[1].hasNext() && !chapterScanners[1].nextLine().equals("</Page4>")) { String nextInputLine = chapterScanners[1].nextLine(); lineScanner = new Scanner(nextInputLine); while(lineScanner.hasNext()) { var = var + lineScanner.nextLine(); } var = var + "\n" + "\n"; } chapterTexts.get(1).add(var); } } System.out.println("Size: " + chapterTexts.get(1).size()); for (int i =0; i < chapterTexts.get(1).size(); i++) { System.out.println(chapterTexts.get(1).get(i)); }
As it printed out all the text from the files, I don't think ti's a Scanner problem that's causing this so posting the documents won't help any.
It says the size of the first one is 9, as it should be. But the size of the second is being reported as 1, though it should be 4. What's going wrong?
I think it's my tags. What's going wrong to make it so that it picks up the tags as part of the read in in the second one but not in the first?
I'm posting the documents after all.
It's something very simple no doubt. It happened before in the last one too. Though I can't find the error this time.