Back-Button in ActionBar NullPointerException

I got an NullPointerException when i click at the back-button in the Actionbar at these lines:

CustomAdapter:

public int getCount() {
    if (taskItems.size() >= 0)
        return taskItems.size();
    return 0;
}

Also in my ListTasksActivity (second Activity, not main):

public class ListTasksActivity extends ListActivity implements AdapterView.OnItemClickListener {
ArrayList<HashMap<String, String>> adapterItems;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent i = getIntent();

    ListView lv = getListView();
    lv.setOnItemClickListener(this);

    ArrayList<HashMap<String, String>> taskItems = (ArrayList<HashMap<String, String>>) i.getSerializableExtra("taskItems");
    String[] stringArr = i.getStringArrayExtra("adapterStringArray");
    int[] intArr = i.getIntArrayExtra("adapterIntArray");

    CustomAdapterTasks adapterTasks = new CustomAdapterTasks(this,taskItems);
    setListAdapter(adapterTasks);
    adapterItems = taskItems;
    //CustomAdapterTasks customAdapterTasks = new CustomAdapterTasks((ListViewActivity) ListViewActivity.getAppContext(),);
}

at: setListAdapter(adapterTasks);

Here my implementation of the Back-Button:

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        getActionBar().setDisplayHomeAsUpEnabled(true);

public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.ueber) {
            startActivity(new Intent(this, menu_main_Activity.class));
            return true;
        }
        switch (item.getItemId()) {
            case android.R.id.home:
                NavUtils.navigateUpFromSameTask(this);
                finish();
                return true;

            default:
                return super.onOptionsItemSelected(item);
        }
    }

Tell me if you want some more code!


Source: android

Leave a Reply