Question about serializing a Location subclass in order to write them to a file
<p>As I understand things, in order to save an ArrayList of objects to a file using ObjectOutputStream, the Objects in the ArrayList need to implement Serializable.</p>

<p>I'm trying to save an ArrayList of Locations to a file, so I extend Location into a class that does that (and nothing else).  So I have a class that looks like...</p>

<pre><code>import java.io.Serializable;

import android.location.Location;

public class MyLocation extends Location implements Serializable{

/**
 * 
 */
private static final long serialVersionUID = 7599200646859829149L;

public MyLocation(Location l) {
    super(l);

}

} 
</code></pre>

<p>But now, in my location listener it crashes at</p>

<pre><code>public void onLocationChanged(Location loc) {
        locat = (MyLocation)loc;
</code></pre>

<p>I suppose it doesn't like the typecasting?  I dunno, I'm a little confused.  Sorry if this is obvious, I haven't been doing this long.</p>

<p>The serialVersionUID line was generated by Eclipse using "add generated serial version ID"</p>

<h3>Update:</h3>

<p>Like I said before, I'm trying to read/write an arraylist of Locations to/from a file.  When I write my data to a file, I don't get any exceptions, but I do get an exception when I try to read it.  Basically I have a class that extends ArrayList (because I needed it to be parseable for Listview purposes...</p>

<pre><code>public class LocationList extends ArrayList&lt;MyLocation&gt; implements Parcelable {


private static final long serialVersionUID = 1L;
</code></pre>

<p>it's a LocationList named waypoints that I write to a file.  This seems to work fine (ie it doesn't throw an exception or crash)...</p>

<pre><code>FileOutputStream fos;
    try {
        fos = context.openFileOutput(fileName, Context.MODE_PRIVATE);
        ObjectOutputStream os;
        os = new ObjectOutputStream(fos);
        os.writeObject(waypoints);   // &lt;-- writeObject doesn't throw an exception.
        os.close();
</code></pre>

<p>but when I try to read that file, I get an IO exception...</p>

<pre><code>FileInputStream fis;

    try {
        fis = context.openFileInput(fileName);
        ObjectInputStream is = new ObjectInputStream(fis);
        is.readObject();   // &lt;--this is the line that throws an IO exception
        is.close();
</code></pre>

<p>This is probably a naive attempt at saving/loading a moderately complicated object.  Any advice?</p>

<p>NOTE: I simplified it a bit.  Originally the offending line was </p>

<pre><code>waypoints = (LocationList) is.readObject(); 
</code></pre>

<p>but I was worried that I had a similar problem with the casting as above so i took it out temporarily.  Anyway, readObject() throws an exception without the typecast there, so I guess that's not my current problem.</p>
