У меня проблема с getParcelableArrayListExtra и исключением нулевого указателя.
Рабочая
Моя активность:
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
fetch = new ArrayList<Custom>();
generateEntries();
Log.i("fetch", fetch.toString());
Intent myIntent = new Intent(this, CustomObject.class);
//myIntent.putParcelableArrayListExtra("my", fetch);
myIntent.putExtra("my", "name");
myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(myIntent);
}
CustomObject:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.customobject);
lv = (ListView) findViewById(R.id.listview);
recievedList = new ArrayList<Custom>();
in = getIntent();
String s = bu.getString("my");
Log.i("s", "s");
}
НЕ работает
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
fetch = new ArrayList<Custom>();
generateEntries();
Log.i("fetch", fetch.toString());
Intent myIntent = new Intent(this, CustomObject.class);
myIntent.putParcelableArrayListExtra("my", fetch);
//myIntent.putExtra("my", "name");
myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(myIntent);
}
CustomObject:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.customobject);
lv = (ListView) findViewById(R.id.listview);
recievedList = new ArrayList<Custom>();
in = getIntent();
recievedList = in.getParcelableArrayListExtra("my"); // NULL POINTER EXCEPTION
}
В чем проблема с ArrayList?
Кто-нибудь поможет мне?
.....................................................................................................
public class Custom implements Parcelable {
private String alarmTitle;
private String alarmType;
private String alarmTime;
private String alarmDate;
private List<String> shortVakatName;
private List<String> vakatActive;
public Custom(String entry1, List<String> list1, List<String> list2, String entry3, String entry4, String entry5){
this.shortVakatName = new ArrayList<String>();
this.vakatActive = new ArrayList<String>();
this.alarmTitle = entry1;
this.shortVakatName = list1;
this.vakatActive = list2;
this.alarmType = entry3;
this.alarmTime = entry4;
this.alarmDate = entry5;
}
private Custom(Parcel in){
alarmTitle = in.readString();
in.readStringList(shortVakatName);
in.readStringList(vakatActive);
alarmTime = in.readString();
alarmDate = in.readString();
}
public static final Parcelable.Creator<Custom> CREATOR =
new Parcelable.Creator<Custom>() {
public Custom createFromParcel(Parcel source) {
return new Custom(source);
}
public Custom[] newArray(int size) {
return new Custom[size];
}
};
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(alarmTitle);
dest.writeStringList(shortVakatName);
dest.writeStringList(vakatActive);
dest.writeString(alarmType);
dest.writeString(alarmTime);
dest.writeString(alarmDate);
}
}