views:

273

answers:

0

I have a simple class:

public class Ball2 extends ImageView implements Serializable {

    public Ball2(Context context) {
        super(context);
    }
}

Serialization ok:

private void saveState() throws IOException {

        ObjectOutputStream oos = new ObjectOutputStream(openFileOutput("data", MODE_PRIVATE));
        try {
            Ball2 data = new Ball2(Game2.this);

            oos.writeObject(data);
            oos.flush();

        } catch (Exception e) {
            Log.e("write error", e.getMessage(), e);
        } finally {
            oos.close();
        }
    }

But deserealization

private void loadState() throws IOException {
        ObjectInputStream ois = new ObjectInputStream(openFileInput("data"));
        try {
            Ball2 data = (Ball2) ois.readObject();
        } catch (Exception e) {
            Log.e("read error", e.getMessage(), e);
        } finally {
            ois.close();
        }
    }

fail with error:

03-24 21:52:43.305: ERROR/read error(1948): java.io.InvalidClassException: android.widget.ImageView; IllegalAccessException

How deserialize object correctly?