I am attempting to make ListView populated from database, and spice each row with fancy remove button. And So I made list Activity and custom SimpleCursorAdapter.

This really is primary ListView activity:

    public class EditEntries extends ListActivity {
    Cursor cursor;
    DBAdapter db = new DBAdapter(this);
    private static String[] FROM = { _ID, SCORE_COLUMN,
            "date(time, 'localtime')", };
    private static int[] TO = { R.id.rowid, R.id.title, R.id.time, };

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.entries_list);
        try {
            cursor = getEvents();
            showEvents(cursor);
        } finally {
            db.close();
        }
    }

    private void showEvents(Cursor cursor) {
        // Set up data binding
        SMSimpleCursorAdapter adapter = new SMSimpleCursorAdapter(this,
                R.layout.entries_list_item, cursor, FROM, TO);
        setListAdapter(adapter);

    }

    private Cursor getEvents() {
        db.open();
        cursor = db.getAllScores();
        startManagingCursor(cursor);
        return cursor;
    }

    void delRow() {        // this is method for deleting row by _id
        db.open();
        db.deleteScore(3); // here will be TAG with _id from adapter,
        db.close();        // for now I just use hardcoded _id
    }

}

Which is custom SimpleCursorAdapter:

    public class SMSimpleCursorAdapter extends SimpleCursorAdapter{

    Cursor c;
    Context context;
    Activity activity;

    public SMSimpleCursorAdapter(Context context, int layout, Cursor c,
            String[] from, int[] to) {
        super(context, layout, c, from, to);

        this.c = c;
        this.context=context;
        this.activity=(Activity) context;

    }
    EditEntries dbDel = new EditEntries(); //from previous code sample

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView == null)
            convertView = View.inflate(context, R.layout.entries_list_item, null);
        View row = convertView;

        c.moveToPosition(position);

        TextView score = (TextView) convertView.findViewById(R.id.title);
        TextView time = (TextView) convertView.findViewById(R.id.time);
        TextView id = (TextView) convertView.findViewById(R.id.rowid);

        id.setText(c.getString(0));
        time.setText(c.getString(2));
        score.setText(c.getString(1));

        String daTag = c.getString(1);

        ImageButton delButton = (ImageButton) convertView.findViewById(R.id.delButton);
        delButton.setFocusable(true);
        delButton.setClickable(true);
        //delButton.setTag(daTag);
        delButton.setOnClickListener(new OnClickListener() { //Click listener fro delete button
             @Override
             public void onClick(View view) {
                 dbDel.delRow(); //this is "delete row" method from previos code                    sample
             }
             });

        return(row);
    }

}

And all sorts of these items provides me with NullPointerException after i click remove button. I am a new comer to android, and guess that I simply skipped something apparent.

LogCat:

ERROR/AndroidRuntime(14027): FATAL EXCEPTION: primary

ERROR/AndroidRuntime(14027): java.lang.NullPointerException

ERROR/AndroidRuntime(14027): at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:203)

ERROR/AndroidRuntime(14027): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:98)

ERROR/AndroidRuntime(14027): at namespace.DBAdapter.open(DBAdapter.java:66)

ERROR/AndroidRuntime(14027): at namespace.EditEntries.delRow(EditEntries.java:50)

ERROR/AndroidRuntime(14027): at namespace.SMSimpleCursorAdapter$1.onClick(SMSimpleCursorAdapter.java:64)

ERROR/AndroidRuntime(14027): at android.view.View.performClick(View.java:2414)

ERROR/AndroidRuntime(14027): at android.view.View$PerformClick.run(View.java:8838)

ERROR/AndroidRuntime(14027): at android.os.Handler.handleCallback(Handler.java:587)

ERROR/AndroidRuntime(14027): at android.os.Handler.dispatchMessage(Handler.java:92)

ERROR/AndroidRuntime(14027): at android.os.Looper.loop(Looper.java:123)

ERROR/AndroidRuntime(14027): at android.application.ActivityThread.primary(ActivityThread.java:4680)

ERROR/AndroidRuntime(14027): at java.lang.reflect.Method.invokeNative(Native Method)

ERROR/AndroidRuntime(14027): at java.lang.reflect.Method.invoke(Method.java:521)

ERROR/AndroidRuntime(14027): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)

ERROR/AndroidRuntime(14027): at com.android.internal.os.ZygoteInit.primary(ZygoteInit.java:616)

ERROR/AndroidRuntime(14027): at dalvik.system.NativeStart.primary(Native Method)