Howdy y'all,
Trying to learn
java is very frustrating!
In the code below I am getting a NullPointerException when I call the size method on the returned TreeSet (second last line). Please shed some light for me. Thanks in advance.
import java.io.*;
import java.util.*;
import java.text.*;
public class Directories2{
// Read the list of directories to populate the jList dialog
String str = new String();
BufferedReader br = null;
public TreeSet getDirName(){
TreeSet theList = new TreeSet();
try{
String line = null;
theList = null;
File inputFile = new File("G:\\E-biz\\Technology Team\\Postal Codes\\Data\\input\\pcfiledirs.txt");
br = new BufferedReader(new InputStreamReader(new FileInputStream(inputFile)));
while ((line = br.readLine())!=null)
{
//str = br.readLine();
// System.out.println(line);
if (str.startsWith("20")){
theList.add(str);
}
}
}
catch (IOException e) {
System.err.println("Caught IOException: "
+ e.getMessage());
}
return theList;
}
public static void main(String[] args) {
Directories2 a = new Directories2();
a.getDirName();
System.out.println ("size " + a.getDirName().size());
System.out.println ("Done");
}
}