Andreas Johansson
Lurker
Hi!
I have been trying to store application specific data in a file. The data is stored in a LinkedList<TaskItem> where TaskItem class holds data.
This is my save method:
This is my load method:
I have tried saving single objects of class TaskItem, and that works. However, when trying t save/load entire LinkedList, it does not! I get the feeling that the object read is not compatible with my linked list, why it is not working as a linked list anymore.
BR,
Andreas
I have been trying to store application specific data in a file. The data is stored in a LinkedList<TaskItem> where TaskItem class holds data.
This is my save method:
Code:
public void saveData()
{
if(LinkedList_taskItems.isEmpty()) {
File f = new File(this.getFilesDir()+"/datafil1.dat");
f.delete();
return;
}
try {
ObjectOutputStream objectOutputStream = new ObjectOutputStream(this.openFileOutput("datafil1.dat", MODE_PRIVATE));
objectOutputStream.writeObject(LinkedList_taskItems);
objectOutputStream.close();
}
catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
This is my load method:
Code:
public void loadData()
{
File f = new File(this.getFilesDir()+"/datafil1.dat");
if(!f.exists())
return;
try {
ObjectInputStream objectinputstream = new ObjectInputStream(this.openFileInput("datafil1.dat"));
LinkedList_taskItems = ((LinkedList<TaskItem>) objectinputstream.readObject());
objectinputstream.close();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (OptionalDataException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (StreamCorruptedException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
finally{
return;
}
}
}
I have tried saving single objects of class TaskItem, and that works. However, when trying t save/load entire LinkedList, it does not! I get the feeling that the object read is not compatible with my linked list, why it is not working as a linked list anymore.
BR,
Andreas
