gpt4 book ai didi

java - Android:异常解码未知类型

转载 作者:行者123 更新时间:2023-12-02 07:39:59 25 4
gpt4 key购买 nike

我必须将 ArrayList 从一个 Activity 传递到另一个 Activity 。所以我使用

intent.putParcelableArrayListExtra("Items",sendinglist);

我通过

获取发送列表
ArrayList<GeoItem> revd = new ArrayList<GeoItem>();
Bundle b = getIntent().getExtras();
if (b != null)
revd = b.getParcelableArrayList("Items");
Log.i("Element details",revd.get(0).getLatitude()+"");// Error

但我无法访问该列表中的 GeoItem 对象。根据答案更新类(class)...

我的 GeoItem 类是

公共(public)类 GeoItem 实现 Parcelable、Serialized {

/** id of item. */
protected long id_;
/** item location in GeoPoint. */
// protected GeoPoint location_;
/** selection state flag. true if selected. */
protected boolean isSelected_;
protected int latitude;
protected int longitude;
protected String incident_no;
protected String title;
protected String date;
protected String address;

/**
* @param id
* item id.
* @param latitudeE6
* latitude of the item in microdegrees (degrees * 1E6).
* @param longitudeE6
* longitude of the item in microdegrees (degrees * 1E6).
*/
public GeoItem(long id, int latitudeE6, int longitudeE6, String inc_no,
String tlt, String dates, String addr) {
id_ = id;
// location_ = new GeoPoint(latitudeE6, longitudeE6);
isSelected_ = false;
incident_no = inc_no;
title = tlt;
date = dates;
address = addr;
latitude=latitudeE6;
longitude=longitudeE6;
}

public long getId_() {
return id_;
}

public void setId_(long id_) {
this.id_ = id_;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getDate() {
return date;
}

public void setDate(String date) {
this.date = date;
}

public String getAddress() {
return address;
}

public void setAddress(String address) {
this.address = address;
}

public void setIncident_no(String incident_no) {
this.incident_no = incident_no;
}

public int getLatitude() {
return latitude;
}

public void setLatitude(int latitude) {
this.latitude = latitude;
}

public int getLongitude() {
return longitude;
}

public void setLongitude(int longitude) {
this.longitude = longitude;
}

/**
* @param src
* source GeoItem
*/
public GeoItem(GeoItem src) {
id_ = src.id_;
// location_ = new
// GeoPoint(src.location_.getLatitudeE6(),src.location_.getLongitudeE6());
isSelected_ = src.isSelected_;
}

/**
* @param src
* source Parcel
*/
public GeoItem(Parcel src) {
id_ = src.readLong();
// location_ = new GeoPoint(src.readInt(), src.readInt());
isSelected_ = src.readInt() == 0 ? false : true;
address = src.readString();
date = src.readString();
}

/* describeContents */
public int describeContents() {
return 0;
}

/**
* getId
*
* @return id of the item.
*/
public long getId() {
return id_;
}

public String getIncident_no() {
return incident_no;
}

/**
* setId
*
* @param id
* of the item.
*/
public void setId(long id) {
id_ = id;
;
}

/**
* getLocation
*
* @return GeoPoint of the item.
*
* public GeoPoint getLocation() { return location_; }
*/
/**
* isSelected
*
* @return true if the item is in selected state.
*/
public boolean isSelected() {
return isSelected_;
}

/**
* setSelect
*
* @param flg
* flag to be set.
*/
public void setSelect(boolean flg) {
isSelected_ = flg;
}

/**
* Parcelable.Creator
*/
public static final Parcelable.Creator<GeoItem> CREATOR = new Parcelable.Creator<GeoItem>() {
public GeoItem createFromParcel(Parcel in) {
return new GeoItem(in);
}

public GeoItem[] newArray(int size) {
return new GeoItem[size];
}
};

/**
* writeToParcel
*
* @param parcel
* Parcel to be written.
* @param flags
* flag.
*/
public void writeToParcel(Parcel parcel, int flags) {
parcel.writeLong(id_);
parcel.writeString(address);
parcel.writeString(date);
parcel.writeInt(latitude);
parcel.writeInt(longitude);
int flg = isSelected_ ? 1 : 0;
parcel.writeInt(flg);
}


}

请给我最好的方法...

最佳答案

GeoPoint不是 Parceable 因此它可以被编码。您可能希望在没有 GeoPoint 的情况下以某种方式保存数据,或者扩展 GeoPoint 以便它实现 Parceable

关于java - Android:异常解码未知类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11734220/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com