我有简单的 Track 类,它存储有关路线的信息:
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import android.location.Location;
public class Track implements Serializable {
private static final long serialVersionUID = -5317697499269650204L;
private Date date;
private String name;
private int time;
private double distance, speed;
private ArrayList<Location> route;
public Track(String name, int time, double distance, ArrayList<Location> route) {
this.date = new Date();
this.name = name;
this.time = time;
this.distance = distance;
this.speed = distance / (time / 3600.);
this.route = route;
}
public String getDate() {
return String.format("Date: %1$td-%1$tb-%1$tY%nTime: %1$tH:%1$tM:%1$tS", date);
}
public String getName() {
return name;
}
public int getTime() {
return time;
}
public double getDistance() {
return distance;
}
public float getSpeed() {
return (float) speed;
}
public ArrayList<Location> getRoute() {
return route;
}
@Override
public String toString() {
return String.format("Name: %s%nDate: %2$td-%2$tb-%2$tY%nTime: %2$tH:%2$tM:%2$tS", name, date);
}
}
我将它从一项活动传递到另一项活动:
Intent showTrackIntent = new Intent(TabSavedActivity.this, ShowTrackActivity.class);
showTrackIntent.putExtra("track", adapter.getItem(position));
startActivity(showTrackIntent);
其中(Track 对象是 ListView 上的元素)。在传递 Track 对象时出现错误:
java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = classes.Track)
怎么了?