Java Android:异常解组未知类型
我必须将ArrayList从一个活动传递到另一个活动。所以我用Java Android:异常解组未知类型,java,android,android-intent,Java,Android,Android Intent,我必须将ArrayList从一个活动传递到另一个活动。所以我用 intent.putParcelableArrayListExtra("Items",sendinglist); 我把发送名单传过去了 ArrayList<GeoItem> revd = new ArrayList<GeoItem>(); Bundle b = getIntent().getExtras(); if (b != null) revd =
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
ArrayList revd=new ArrayList();
Bundle b=getIntent().getExtras();
如果(b!=null)
revd=b.getParcelableArrayList(“项目”);
Log.i(“元素详细信息”,revd.get(0.getLatitude()+);//错误
但我无法访问该列表中的GeoItem对象。
根据答案更新课程
我的GeoItem类是
公共类GeoItem实现可包裹、可序列化{
/** 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);
}
}
/**项目的id*/
受保护的长id;
/**项目在地质点中的位置*/
//保护地质点位置;
/**选择状态标志。如果选择,则为true*/
受保护的布尔值;
受保护的国际纬度;
受保护的经度;
受保护字符串事件编号;
受保护的字符串标题;
保护字符串日期;
受保护的字符串地址;
/**
*@param-id
*项目id。
*@param latitudeE6
*项目的纬度(微度*1E6)。
*@param longitudeE6
*项目的经度(微度*1E6)。
*/
公共地理项目(长id、内纬度E6、内纬度E6、字符串编号、,
字符串tlt、字符串日期、字符串地址){
id=id;
//位置=新的地质点(纬度E6、纬度E6);
isSelected=假;
事件编号=公司编号;
标题=tlt;
日期=日期;
地址=地址;
纬度=纬度6;
经度=经度6;
}
公共长getId_u389;(){
返回id_u2;;
}
公共无效集合id(长id){
this.id=id;
}
公共字符串getTitle(){
返回标题;
}
公共无效集合标题(字符串标题){
this.title=标题;
}
公共字符串getDate(){
返回日期;
}
公共无效设置日期(字符串日期){
this.date=日期;
}
公共字符串getAddress(){
回信地址;
}
公共无效设置地址(字符串地址){
this.address=地址;
}
公共事件编号(字符串事件编号){
this.incident\u no=事件号;
}
公共整数getLatitude(){
返回纬度;
}
公共空间设置纬度(整数纬度){
这个。纬度=纬度;
}
公共int getLongitude(){
返回经度;
}
公共空间设置经度(整数经度){
这个经度=经度;
}
/**
*@param src
*源地理项
*/
公共地理项目(地理项目src){
id=src.id;
//位置=新
//地理点(src.location\uu0.getLatitudeE6(),src.location\u0.getLongitudeE6());
isSelected=src.isSelected;
}
/**
*@param src
*源地块
*/
公共地理项目(src地块){
id=src.readLong();
//位置=新的地质点(src.readInt(),src.readInt());
isSelected=src.readInt()==0?false:true;
address=src.readString();
date=src.readString();
}
/*描述内容*/
公共int描述内容(){
返回0;
}
/**
*盖蒂
*
*@returnid是该物品的返回id。
*/
公共长getId(){
返回id_u2;;
}
公共字符串getIncident_no(){
返回事件编号;
}
/**
*setId
*
*@param-id
*这是该项目的一部分。
*/
公共无效集合id(长id){
id=id;
;
}
/**
*获取位置
*
*@返回项目的地理点。
*
*公共地质点getLocation(){返回位置}
*/
/**
*当选
*
*@如果项目处于选定状态,则返回true。
*/
公选{
返回被选中的;
}
/**
*集选
*
*@param flg
*要设置的标志。
*/
公共无效集合选择(布尔flg){
isSelected=flg;
}
/**
*可包裹的,创造者
*/
public static final Parcelable.Creator=新建Parcelable.Creator(){
公共地理项目createFromParcel(中的地块){
返回新的GeoItem(在中);
}
公共地理项目[]新数组(整数大小){
返回新的GeoItem[大小];
}
};
/**
*写包裹
*
*@param包裹
*要写的包裹。
*@param标志
*旗帜。
*/
公共无效writeToParcel(Parcel-Parcel,int标志){
包裹的书写长度(id_);
包裹。书面记录(地址);
包裹书面记录(日期);
包裹书写(纬度);
包裹书写(经度);
int flg=1:0;
包裹书写(flg);
}
}
请给我提供最好的方法…不是可分组的,因此可以编组。您可能希望以某种方式保存数据,而不使用GeoPoint
,或者扩展GeoPoint
,这样它就实现了parsable
**将类别的数组列表传递给另一个活动,**
**To pass an arraylist of Category to another activity,**
intent i = new Intent(_av.getContext(), ItemList.class);
Bundle b = new Bundle();
b.putParcelableArrayList("categories", categories);
b.putInt("index", _index);
i.putExtras(b);
startActivityForResult(i, ITEM_LIST);
**To retrieve the data,**
Bundle b = this.getIntent().getExtras();
ArrayList<Category> cats = b.getParcelableArrayList("categories");
int index = b.getInt("index");
intent i=新的intent(_av.getContext(),ItemList.class);
Bundle b=新Bundle();
b、 putParcelableArrayList(“类别”,categories);
b、 putInt(“索引”、_索引);
i、 putExtras(b);
startActivityForResult(i,项目清单);
**要检索数据**
Bundle b=this.getIntent().getExtras();
ArrayList cats=b.getParcelableArrayList(“类别”);
int index=b.getInt(“索引”);
我的实际任务是通过intent发送GeoItems对象列表。我的GeoItems类也是可序列化的。显然,可序列化对象的列表也是可序列化的,所以我使用
Intent listview = new Intent(context, ReportList.class);
Bundle send = new Bundle();
send.putSerializable("Items", (Serializable) items);
listview.putExtras(send);
context.startActivity(listview);
其中items是GeoIems对象的列表
在接待活动中,
Bundle b = this.getIntent().getExtras();
if (b != null) {
data = (List<GeoItem>) b.getSerializable("Items");
}
Bundle b=this.getIntent().getExtras();
如果(b!=null){
数据=(列表)b.getSerializable(“项”);
}
其中数据是GeoIems对象的列表
不使用Parsable接口,现在我可以通过intent to next activity设置可序列化对象的列表我已经从GeoItem类中删除了该地理点,而是添加了两个成员,如latitude和longitude。但还是同样的错误