I am trying to add data from a CSV file into a list. At the moment I have this code below, however the application closes whenever I try to run it.
private HashMap<String, GeoLocation> loadLocationData() {
String csvFile = "C:\\Users\\MyName\\Documents\\MyApplication\\app\\src\\main\\res\\raw\\geo_locations.csv";
String line = "";
String cvsSplitBy = ",";
try (BufferedReader br = new BufferedReader(new FileReader(csvFile))) {
while ((line = br.readLine()) != null) {
String[] cityloc = line.split(cvsSplitBy);
locations.put(cityloc[0], new GeoLocation(cityloc[0], Double.parseDouble(cityloc[1]), Double.parseDouble(cityloc[2]), TimeZone.getTimeZone(cityloc[3])));
}
} catch (IOException e) {
e.printStackTrace();
}
return locations;
}
I have already asked about reading CSV files and was given a list of other questions on it, however, after working on it I have not been able to resolve my problem here.
The basic gist of what I need to do, is get that list from the CSV file, and create a list from it that I can add to "locations".