I'm trying to deserialize an object but it doesn't work.
Has anyone an idea how to handle it?
public static List<Leistung> findAll(Context ctx) {
List<Leistung> result = null;
FileInputStream in = null;
Object obj = null;
File f = ctx.getFileStreamPath("file.obj");
if (f.exists()) {
try {
in = ctx.openFileInput("file.obj");
ObjectInputStream objIn = new ObjectInputStream(in);
// obj = objIn.readObject();
obj = (ArrayList<Leistung>) objIn.readObject();
} catch (Exception e) {
Log.v(TAG, "read Failed");
e.printStackTrace();
} finally {
try {
in.close();
} catch (IOException e) {
Log.v(TAG, "close failed");
e.printStackTrace();
}
}
}
if (obj != null) {
result = (List<Leistung>) obj;
} else {
result = new ArrayList<Leistung>();
}
return result;
}
public static void persistAll(Context ctx, List<Leistung> leistungen) {
FileOutputStream out = null;
try {
out = ctx.openFileOutput("file.obj", Context.MODE_PRIVATE);
ObjectOutputStream objOut = new ObjectOutputStream(out);
objOut.writeObject(leistungen);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
10-17 12:02:10.911: WARN/System.err(16429): java.io.InvalidClassException: de.moelders.notensammlerapp.Modul; IllegalAccessException 10-17 12:02:10.921: WARN/System.err(16429): at java.io.ObjectInputStream.resolveConstructorClass(ObjectInputStream.java:2010) 10-17 12:02:10.921: WARN/System.err(16429): at java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:2095) 10-17 12:02:10.931: WARN/System.err(16429): at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:929) 10-17 12:02:10.941: WARN/System.err(16429): at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2285) 10-17 12:02:10.941: WARN/System.err(16429): at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2240) 10-17 12:02:10.941: WARN/System.err(16429): at java.util.ArrayList.readObject(ArrayList.java:662) 10-17 12:02:10.951: WARN/System.err(16429): at java.lang.reflect.Method.invokeNative(Native Method) 10-17 12:02:10.951: WARN/System.err(16429): at java.lang.reflect.Method.invoke(Method.java:521) 10-17 12:02:10.961: WARN/System.err(16429): at java.io.ObjectInputStream.readObjectForClass(ObjectInputStream.java:1537) 10-17 12:02:10.971: WARN/System.err(16429): at java.io.ObjectInputStream.readHierarchy(ObjectInputStream.java:1460) 10-17 12:02:10.971: WARN/System.err(16429): at java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:2139) 10-17 12:02:10.981: WARN/System.err(16429): at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:929) 10-17 12:02:10.981: WARN/System.err(16429): at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2285) 10-17 12:02:10.991: WARN/System.err(16429): at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2240) 10-17 12:02:10.991: WARN/System.err(16429): at de.moelders.notensammlerapp.Storage.findAll(Storage.java:33) 10-17 12:02:11.001: WARN/System.err(16429): at de.moelders.notensammlerapp.NoteListe.onStart(NoteListe.java:21)