看看我的代码,是否有错。
活动一:
"com.chishacai.smscenter.bean.PickBean,但得到的是空值"
请帮我处理这个问题,谢谢。
活动一:
Intent intent = new Intent(SendActivity.this, PickContactsActivity.class);
startActivityForResult(intent, 20);
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
ArrayList<PickBean> cons = data.getParcelableArrayListExtra("data");
for (int i = 0; i < cons.size(); i++) {
JLog.e(LOG_TAG, "displayName:" + cons.get(i).displayName + "displayNumber" + cons.get(i).displayNumber);
}
}
}
活动二:
Intent data = new Intent();
ArrayList<PickBean> cons = new ArrayList<PickBean>();
for (int i = 0; i < conData.size(); i++) {
cons.add(new PickBean(conData.get(i).displayName, conData.get(i).displayNumber));
}
}
data.putParcelableArrayListExtra("data", cons);
setResult(RESULT_OK, data);
finish();
选取豆代码:
public class PickBean implements Parcelable {
public String displayName;
public String displayNumber;
public boolean selected = false;
public PickBean() {
super();
}
public PickBean(String displayName, String displayNumber) {
super();
this.displayName = displayName;
this.displayNumber = displayNumber;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(displayName);
dest.writeString(displayNumber);
}
public final Parcelable.Creator<PickBean> CREATOR = new Parcelable.Creator<PickBean>() {
@Override
public PickBean createFromParcel(Parcel source) {
return new PickBean(source.readString(), source.readString());
}
@Override
public PickBean[] newArray(int size) {
return new PickBean[size];
}
};
}
它总是会抛出异常
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=20,
result=-1, data=Intent { (has extras) }} to activity
{com.chishacai.smscenter/com.chishacai.smscenter.SendActivity}: java.lang.NullPointerException: expected receiver of type
"com.chishacai.smscenter.bean.PickBean,但得到的是空值"
Caused by: java.lang.NullPointerException: expected receiver of type
com.chishacai.smscenter.bean.PickBean, but got null
请帮我处理这个问题,谢谢。
putParcelableArrayList("data", cons);
传递时,请确保您的数组con
不为空。 - SweetWisher ツ