I am trying the solution in the top answer here: Android ArrayList of custom objects - Save to SharedPreferences - Serializable?
I am trying to save to SharedPreferences an ArrayList of custom objects.
SharedPreferences appSharedPrefs = PreferenceManager.getDefaultSharedPreferences(baseApplication);
SharedPreferences.Editor prefsEditor = appSharedPrefs.edit();
Gson gson = new Gson();
String json = gson.toJson(masterPinList);
prefsEditor.putString("masterPinList", json);
prefsEditor.apply();
masterPinList
is an ArrayList of custom objects (Pin
).
The error is:
java.lang.SecurityException: Can not make a java.lang.reflect.Method constructor accessible
The error occurs at this line:
String json = gson.toJson(masterPinList);
What is wrong?
Pin
– weston