[Solved] My app keeps crashing, Cursor is not initialized correctly


It’s typically an inflation error. You would need to compare the View IDs that you are attempting to populate, make sure they are not null and that you are setup with your Recycler View Holder Adapter properly.

Post your adapter, your xml for the row that you are filling, your viewholder pattern and your adapter setup and assignment and we can certainly get you squared away.

Just to update the answer your cursor should be populated properly before accessing it and you should ensure the content exists before accessing it.

EXAMPLE populating Cursor

    Cursor cursor = null;
        try {
            cursor = queryBuilder.query(MySQLDBHelper.openDatabase(<YOUR CONTEXT>), projection, selection, selectionArgs, null, null, sortOrder);

        } catch (Exception e) {
            e.printStackTrace();
        }
return cursor;

Next when you decide to access values from the cursor you can do some safe checks instead of directly accessing them. It can get rather verbose so I would recommend making a method that creates your object from the cursor and then do all your null safe checks there.

Instead of:

mCursor.getString(mCursor.getColumnIndex(WorkersContract.Columns.IBU_KANDUNG)));

Do something like:

int IBU_KANDUNG_INDEX = mCursor.getColumnIndex(WorkersContract.Columns.IBU_KANDUNG);
myObject.setString(mCursor.getString(IBU_KANDUNG_INDEX) == null ? "" : mCursor.getString(IBU_KANDUNG_INDEX));

This will ensure you are not setting null values into your object or trying to access -1 index of a cursor that is empty.

3

solved My app keeps crashing, Cursor is not initialized correctly