我正在尝试使我的对象 Parcelable。我有以下代码用于从包裹创建对象以及写入包裹的函数。当尝试从包裹创建对象时,我在创建 m_endTime 时遇到错误,它说它不能将字符串转换为 Long。不太清楚发生了什么。
private RECTripFishery(Parcel in) {
m_tripId = (Integer) in.readValue(null);
m_fishery = (String) in.readValue(null);
m_targetSpecies = (String) in.readValue(null);
m_startTime = new Date((Long) in.readValue(null));
if (in.readValue(null) == null){
m_endTime = null;
} else {
m_endTime = new Date((Long) in.readValue(null));
}
m_startLatitude = (Double) in.readValue(null);
m_startLongitude = (Double) in.readValue(null);
m_endLatitude = (Double) in.readValue(null);
m_endLongitude = (Double) in.readValue(null);
}
@Override
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeValue(Integer.valueOf(m_tripId));
dest.writeValue(m_fishery);
dest.writeValue(m_targetSpecies);
dest.writeValue(Long.valueOf(m_startTime.getTime()));
if (m_endTime == null) {
dest.writeValue(null);
} else {
dest.writeValue(Long.valueOf(m_endTime.getTime()));
}
dest.writeValue(m_startLatitude);
dest.writeValue(m_startLongitude);
dest.writeValue(m_endLatitude);
dest.writeValue(m_endLongitude);
return;
}private RECTripFishery(Parcel in) {
m_tripId = (Integer) in.readValue(null);
m_fishery = (String) in.readValue(null);
m_targetSpecies = (String) in.readValue(null);
m_startTime = new Date((Long) in.readValue(null));
if (in.readValue(null) == null){
m_endTime = null;
} else {
m_endTime = new Date((Long) in.readValue(null));
}
m_startLatitude = (Double) in.readValue(null);
m_startLongitude = (Double) in.readValue(null);
m_endLatitude = (Double) in.readValue(null);
m_endLongitude = (Double) in.readValue(null);
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeValue(Integer.valueOf(m_tripId));
dest.writeValue(m_fishery);
dest.writeValue(m_targetSpecies);
dest.writeValue(Long.valueOf(m_startTime.getTime()));
if (m_endTime == null) {
dest.writeValue(null);
} else {
dest.writeValue(Long.valueOf(m_endTime.getTime()));
}
dest.writeValue(m_startLatitude);
dest.writeValue(m_startLongitude);
dest.writeValue(m_endLatitude);
dest.writeValue(m_endLongitude);
return;
}