Skip to content Skip to sidebar Skip to footer

Simplecursoradapter Isn't Working

I have been following one of google developers tutorials about creating an application with storing added items to database and retriving them to listView, but they are using ListA

Solution 1:

The reason you're getting a NullPointerException is because you're calling listView.setAdapter(items); before calling listView = (ListView) findViewById(R.id.list);.

Just move the call to fillData() below the call that initializes listView:

    mDbHelper = new GroceryDbAdapter(this);
    mDbHelper.open();
    //fillData(); //don't call it here// Locate ListView
    listView = (ListView) findViewById(R.id.list);

    fillData(); //call it here

As for your next NullPointerException, you need to initialize saveButton before you call saveButton.setOnClickListener().

Something like this:

saveButton = (Button) findViewById(R.id.yourButtonIdHere);

saveButton.setOnClickListener(newView.OnClickListener() {

            publicvoidonClick(View view) {
                setResult(RESULT_OK);
                finish();
            }

        });

Solution 2:

You need to call method:

fillData()

after this assignment:

listView = (ListView) findViewById(R.id.list).

Post a Comment for "Simplecursoradapter Isn't Working"