I am not sure my i am getting NullPointerException exception i am new to java can anybody please help on this.
Code i am using for this -
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
public class sortNumberOfFile {
public static void main(String[] args) throws IOException,
InterruptedException {
HashSet<String> hs = null;
String perLine;
String filename = "C:\\Users\\dummy\\Downloads\\ip.txt";
BufferedReader br = new BufferedReader(new FileReader(filename));
while ((perLine = br.readLine()) != null) {
System.out.println("whole line : " + perLine);
String[] eachLine = perLine.split(",");
System.out.println("custom element " + eachLine[0] + " "
+ eachLine[2] + " count " + eachLine.length);
for (String str : eachLine) {
System.out.println("Adding "+str);
//Thread.sleep(2000);
hs.add(str);
}
// Collections.addAll(hs, eachLine);
System.out.println(hs);
}
}
}
Console Output i am getting -
whole line : 1,2,32,4,5,234,6,12,3,67,3421,123,2,2,34,5,4
custom element 1 32 count 17
Adding 1
Exception in thread "main" java.lang.NullPointerException
at org.gour.indrajeet.practice.sortNumberOfFile.main(sortNumberOfFile.java:27)