I'm looping a buffered reader to pull lines from a dictionary, add them to an ArrayList, and then run them later in the program. Throughout this 15,000,000 line dictionary, blank lines come up about once every 30,000 lines. I don't expect all users of this program to use the dictionary I include, and I don't want to manually pick out and erase each blank line. When the program encounters this line, it throws a pesky NullPointerException, killing the program immediately. I've tried adding a try/catch to add the line if it's not blank and pass over a line that is null using continue
. As always, here's my code:
String line;
if ((line = br.readLine()) != null) {
try{
passwordArray.add(line);
System.out.println(line);
} catch(NullPointerException npe){
System.out.println("The line is null.");
continue;
}
}
Stack Trace:
Exception in thread "main" java.lang.NullPointerException
at net.lingala.zip4j.core.ZipFile.setPassword(ZipFile.java:650)
at zZipCracker.zZipCracker.zZipCracker(zZipCracker.java:96)
at zZipCracker.zZipCracker.main(zZipCracker.java:55)
Line 96:
zipper.setPassword((String) passwordArray.get(0));
Looking at line 96, the blank line is being added and cannot run because the library I'm using requires a password that's length is greater than 0. Line 55 is just a call to the method where this entire process is completed.