I have a function which is supposed to work with given ArrayList<String>
and return the output as ArrayList<Integer>
. The problem is NullPointerException
is raised on hourList.add(hourInt);
and I don't know why.
public ArrayList<Integer> takeTime(ArrayList<String> logs) {
ArrayList<Integer> hourList=null;
Integer hourInt;
for(String line: logs) {
String[] matrix = line.split(" ");
String[] hour = matrix[3].split(":");
// System.out.print(hour[0]+"\n");
String s = hour[0].replaceFirst("^0+(?!$)", "");
hourInt = Integer.parseInt(s);
System.out.print(hourInt+",");
hourList.add(hourInt); // <--- NullPointerException here
}
return hourList;
}
System.out.print(hourInt+",");
:
0,0,0,0,1,1,2,3,4,4,4,4,4,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,10,10,10,10,10,10,10