Null pointer exception fixed when file reading