I'm making an android app, and I need to save the double value(BodySize) to a file in a form of List to draw a graph. Actually this code was in form of 'List' and I tried to change it into 'List'. But it makes error in 'list.add(BodySize)'. How can I fix this problem?
public static void updateFile(double BodySize) {
FileOutputStream fos = null;
ObjectOutputStream oos = null;
try{
List<double[]> list = getDoubles();
list.add(BodySize);
fos = new FileOutputStream("user_data.txt");
oos = new ObjectOutputStream(fos);
oos.writeObject(list);
}catch(Exception e){
e.printStackTrace();
try {
oos.close();
fos.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
public static List<double[]> getDoubles() {
FileInputStream fis = null;
ObjectInputStream ois = null;
List<double[]> newList = new ArrayList<double[]>>();
try {
fis = new FileInputStream("user_data.txt");
ois = new ObjectInputStream(fis);
newList = (ArrayList<double[]>) ois.readObject();
} catch (Exception ex) {
try {
fis.close();
ois.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return newList;
}