我有这堂课:
public class SaveState implements Serializable {
private static final long serialVersionUID = 1L;
public List<String> downloadedMagazinesIds = new ArrayList<String>();//id's de revistas descargadas
public List<String> downloadedMagazinesSummaries = new ArrayList<String>();//página sumario de cada magazine
public List<FullMagazine> downloadedMagazines = new ArrayList<FullMagazine>();//todos los magazines bajados
public Magazines ms=null; //Esta clase contiene el array de previews de revistas generado con el parser de XML
}
我使用这些方法将类(SaveState 对象)存储在 sdcard 中,并再次将文件中的对象读取到对象中:
public static void saveData(){
ObjectOutput out;
try {
//primero comprobamos si existe el directorio, y si no, lo creamos.
File folder = new File(Environment.getExternalStorageDirectory() + "/C/");
if(!folder.exists())
folder.mkdirs();
File outFile = new File(Environment.getExternalStorageDirectory(), "/C/appSaveState.data");
out = new ObjectOutputStream(new FileOutputStream(outFile));
out.writeObject(saveState);
out.close();
} catch (Exception e) {e.printStackTrace();}
}
public static void loadData(){
ObjectInput in;
try {
File inFile = new File(Environment.getExternalStorageDirectory(), "/C/appSaveState.data");
in = new ObjectInputStream(new FileInputStream(inFile));
saveState=(SaveState) in.readObject();
in.close();
} catch (Exception e) {e.printStackTrace();}
}
我存储对象,每次我的应用程序关闭时,我每次打开我的应用程序时都从 sdcard 读取对象,它工作正常。当我创建更新版本的应用程序(1.01)时,问题就来了。当我启动应用程序并尝试从 sdcard 读取文件时,文件被读取,但对象类的所有变量都是空的,而且它们真的不为空。
为什么我的代码不能正常工作?我应该怎么做才能修复它?