It's not even reading in every page, I've found, either.try { chapterScanners[0] = new Scanner(new File("./s3c1.txt")); } catch(FileNotFoundException fnfe) { } chapterTexts = new ArrayList<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(1).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(2).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(3).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(4).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(5).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); } }
Why the Null Pointers and page ignoring?
It's ignoring all the odd numbered pages. That might be causing the Null Pointer. The question is, why is it doing that?
I do have a title thingy at the beginning, for the chapter heading
Chapter One
Chapter Heading
_____________________________
Like that.
Is that screwing it up?
Also, in addition to not reading in the odd pages, it doesn't appear to be reading in the words
<Page 2></Page2> <Page4></Page4><Page6></Page6> etc, either, though it prints out the
<Page1></Page1><Page3></Page3><Page5></Page5> but has no text.
Basically the even ones don't have the tags but have text and the odd ones have tags but no text.
Why is this happening?