I have an app that fetches uri and name of the images and returns arrayList
of ArrayList<ImageModel>
. Where Image Model consists uri
and name
two variables and Getter
and Setter
for each.
try {
FileOutputStream outputStreamWriter = getContext().openFileOutput("config.txt", Context.MODE_PRIVATE);
ObjectOutputStream oos = new ObjectOutputStream(outputStreamWriter);
oos.writeObject(arrayList);
oos.close();
outputStreamWriter.close();
} catch (IOException e) {
Log.e("Exception", "File write failed: " + e.toString());
}
When I try to save arrayList
Using above methid it throws java.io.NotSerializableException: android.net.Uri$HierarchicalUri
Exception. But, my ImageModel
implementsSerializable
.
try {
FileInputStream fis = getContext().openFileInput("config.txt");
ObjectInputStream ois = new ObjectInputStream(fis);
Object object = ois.readObject();
return object;
} catch (Exception ex) {
return null;
}
Because File is not written it makes this read method return null. So, I need suitable solution to save that arrayList
to local storage and retrive it. Further I am going to load images uri by arrayList.get()
method. So, I suppose ArrayList
is must.