Java getParcelableArrayList返回整数值
我有一个自定义类的Java getParcelableArrayList返回整数值,java,android,parcelable,Java,Android,Parcelable,我有一个自定义类的ArrayList,可以从一个活动传递到另一个活动。我使类实现了可包裹的。但是,每次使用传递的ArrayList时,我都会得到NullPointException。 所以我决定检查getParcelableArrayList()返回值的类,得到java.lang.Integer。我不知道如何解释这一点 第一个活动的代码: public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long ar
ArrayList
,可以从一个活动传递到另一个活动。我使类实现了可包裹的。但是,每次使用传递的ArrayList时,我都会得到NullPointException
。
所以我决定检查getParcelableArrayList()返回值的类,得到java.lang.Integer。我不知道如何解释这一点
第一个活动的代码:
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
Intent intent = new Intent(this, WeiboBrowseActivity.class);
intent.putParcelableArrayListExtra(WeiboBrowseActivity.KEY_WEIBO_INFO_LIST, weiboInfoList);
intent.putExtra(WeiboBrowseActivity.KEY_SELECTED_WEIBO_INDEX, arg2);
startActivity(intent);
overridePendingTransition(R.anim.in_from_right, R.anim.out_to_left);
}
private void initWeiboInfos() {
Log.d("cosmo","the type is: " + getIntent().getExtras().get(KEY_WEIBO_INFO_LIST).getClass().getName());
weiboInfos = getIntent().getExtras().getParcelableArrayList(KEY_WEIBO_INFO_LIST);
if (weiboInfos == null) {
Log.d("cosmo", "weiboInfos null"); //I got this log
} else {
Log.d("cosmo", "weiboInfos not null");
}
}
public class WeiboInfo implements Parcelable {
private String absolutePath;
private long createTimestamp;
public WeiboInfo() {
super();
this.setAbsolutePath("");
this.setCreateTimestamp(new Date().getTime());
}
public WeiboInfo(String absolutePath, long createTimestamp) {
super();
this.setAbsolutePath(absolutePath);
this.setCreateTimestamp(createTimestamp);
}
public WeiboInfo(Parcel in) {
super();
this.setAbsolutePath(in.readString());
this.setCreateTimestamp(in.readLong());
}
public String getAbsolutePath() {
return absolutePath;
}
public void setAbsolutePath(String absolutePath) {
this.absolutePath = absolutePath;
}
public long getCreateTimestamp() {
return createTimestamp;
}
public void setCreateTimestamp(long createTimestamp) {
this.createTimestamp = createTimestamp;
}
@Override
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
// TODO Auto-generated method stub
dest.writeString(absolutePath);
dest.writeLong(createTimestamp);
}
public void readFromParcel(Parcel in) {
absolutePath = in.readString();
createTimestamp = in.readLong();
}
public static final Parcelable.Creator<WeiboInfo> CREATOR = new Parcelable.Creator<WeiboInfo>() {
public WeiboInfo createFromParcel(Parcel in) {
return new WeiboInfo(in);
}
public WeiboInfo[] newArray(int size) {
return new WeiboInfo[size];
}
};
}
包裹类别的代码:
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
Intent intent = new Intent(this, WeiboBrowseActivity.class);
intent.putParcelableArrayListExtra(WeiboBrowseActivity.KEY_WEIBO_INFO_LIST, weiboInfoList);
intent.putExtra(WeiboBrowseActivity.KEY_SELECTED_WEIBO_INDEX, arg2);
startActivity(intent);
overridePendingTransition(R.anim.in_from_right, R.anim.out_to_left);
}
private void initWeiboInfos() {
Log.d("cosmo","the type is: " + getIntent().getExtras().get(KEY_WEIBO_INFO_LIST).getClass().getName());
weiboInfos = getIntent().getExtras().getParcelableArrayList(KEY_WEIBO_INFO_LIST);
if (weiboInfos == null) {
Log.d("cosmo", "weiboInfos null"); //I got this log
} else {
Log.d("cosmo", "weiboInfos not null");
}
}
public class WeiboInfo implements Parcelable {
private String absolutePath;
private long createTimestamp;
public WeiboInfo() {
super();
this.setAbsolutePath("");
this.setCreateTimestamp(new Date().getTime());
}
public WeiboInfo(String absolutePath, long createTimestamp) {
super();
this.setAbsolutePath(absolutePath);
this.setCreateTimestamp(createTimestamp);
}
public WeiboInfo(Parcel in) {
super();
this.setAbsolutePath(in.readString());
this.setCreateTimestamp(in.readLong());
}
public String getAbsolutePath() {
return absolutePath;
}
public void setAbsolutePath(String absolutePath) {
this.absolutePath = absolutePath;
}
public long getCreateTimestamp() {
return createTimestamp;
}
public void setCreateTimestamp(long createTimestamp) {
this.createTimestamp = createTimestamp;
}
@Override
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
// TODO Auto-generated method stub
dest.writeString(absolutePath);
dest.writeLong(createTimestamp);
}
public void readFromParcel(Parcel in) {
absolutePath = in.readString();
createTimestamp = in.readLong();
}
public static final Parcelable.Creator<WeiboInfo> CREATOR = new Parcelable.Creator<WeiboInfo>() {
public WeiboInfo createFromParcel(Parcel in) {
return new WeiboInfo(in);
}
public WeiboInfo[] newArray(int size) {
return new WeiboInfo[size];
}
};
}
你想把一个列表从一个活动传递到另一个活动吗?你能发布关键选定的微博索引和关键微博信息列表吗?playmaker420:是的,这是我的目标。对不起,我的英语不好。布莱克贝尔:我已经更新了问题并贴出了两个键~