我把意圖我用下面的代碼對象(而把名單確實存在,我在調試器中選中)將序列化爲意圖不工作
Intent intent = new Intent(getApplicationContext(), ProductActivity.class);
intent.putExtra("product", CategoryActivity.this.list.get(position));
startActivity(intent);
然後retrive
Intent intent = getIntent();
product = (Product) intent.getSerializableExtra("product");
但它是空
Model類是繼
public class Product implements Serializable {
Integer pk;
String name;
String description;
Integer price;
String image_url;
List<Option> options;
public Product(Integer pk, String name, String description, Integer price, String image_url, List<Option> options) {
this.pk = pk;
this.name = name;
this.description = description;
this.price = price;
this.image_url = image_url;
this.options = options;
}
public Integer getPk() {
return pk;
}
public void setPk(Integer pk) {
this.pk = pk;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Integer getPrice() {
return price;
}
public void setPrice(Integer price) {
this.price = price;
}
public String getImage_url() {
return image_url;
}
public void setImage_url(String image_url) {
this.image_url = image_url;
}
public List<Option> getOptions() {
return options;
}
public void setOptions(List<Option> options) {
this.options = options;
}
}
我在做什麼錯?
你也檢查list.get(位置)沒有返回null? – lelloman
您是否正在使用'startActivity(intent)'重新啓動已經啓動的活動? –