我有一个 todolist 应用程序,我无法将一个活动中的自定义列表传递给另一个活动。我使用数据包装器,但是当我单击添加按钮时,程序给出了 nullpointerexception。
这是 AddItem.java
okButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
ArrayList<Entry> itemList = new ArrayList<Entry>();
task = editText1.getText().toString();
priorityLevel = spinner.getSelectedItem().toString();
status = toggleButton.getText().toString();
int day = datePicker.getDayOfMonth();
int month = datePicker.getMonth() + 1;
int year = datePicker.getYear();
date = day + "/" + month + "/" + year;
itemList.add(new Entry(task, priorityLevel, date, status));
Intent okIntent = new Intent();
okIntent.putExtra("item",new DataWrapper(itemList));
setResult(Activity.RESULT_OK, okIntent);
finish();
}
});
和 MainActivity.java
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
switch (requestCode) {
case ADD_NOTE:
Log.w("1", "one");
DataWrapper dw = (DataWrapper) getIntent().getSerializableExtra("item");
Log.w("2", "two");
entryList = dw.getEntryList();
Log.w("3", "three");
//String extraName = AddItem.code;
//ArrayList<Entry> list = data.getParcelableArrayListExtra(extraName);
todoItems.addAll(entryList);
Log.w("4", "four");
todoArrayAdapter.notifyDataSetChanged();
Log.w("5", "five");
break;