Saving the data works no problem. But when loading the data I get this error message
A/libc﹕ Fatal signal 11 (SIGSEGV), code 1, fault addr 0xa3907e44 in tid 2407 (myapplication)
This method saves the data using googles GSON library. The class is part of an adapter and is called every time the user presses a button in a dialog.
public int saveListToFile(UserData data, Context context) {
itemsData.add(data);
notifyItemInserted(itemsData.size()-1);
String filename = "colors";
File file = new File(context.getFilesDir(), filename);
try {
BufferedWriter buffWriter = new BufferedWriter(new FileWriter(file, true));
Gson gson = new Gson();
Type type = new TypeToken<List<UserData>>() {}.getType();
String json = gson.toJson(itemsData, type);
buffWriter.append(json);
buffWriter.newLine();
buffWriter.close();
} catch (IOException e) {
return -1;
}
return 0;
}
This method loads the data using googles GSON library. This method also causes the app to crash giving the error see above
public int readCurrentList() {
String filename = "colors";
File file = new File(getFilesDir(), filename);
try {
BufferedReader buffReader = new BufferedReader(new FileReader(file));
String line;
Gson gson = new Gson();
Type type = new TypeToken<List<UserData>>() {}.getType();
while ((line = buffReader.readLine()) != null) {
itemsData.addAll((java.util.Collection<? extends UserData>) gson.fromJson(line, type));
}
buffReader.close();
} catch (IOException e) {
return -1;
}
return 0;
}