Wrote a method to get a record on the specified id:
public NotesData getInboxItemByID(String id){ db = dbHelper.getReadableDatabase(); cursor = db.query(DataBaseContract.NotesData.TABLE_NAME, new String[] {DataBaseContract.NotesData._ID}, DataBaseContract.NotesData._ID + "=?", new String[] {id}, null, null, null); int idColInd = cursor.getColumnIndex(DataBaseContract.NotesData._ID); int dateAndTimeColInd = cursor.getColumnIndex(DataBaseContract.NotesData.COLUMN_DATETIME); int titleColInd = cursor.getColumnIndex(DataBaseContract.NotesData.COLUMN_TITLE); int noteTextColInd = cursor.getColumnIndex(DataBaseContract.NotesData.COLUMN_NOTE); NotesData notesData = new NotesData(cursor.getString(idColInd), cursor.getLong(dateAndTimeColInd), cursor.getString(titleColInd), cursor.getString(noteTextColInd)); dbHelper.close(); db.close(); return notesData; } The application crashes with this error:
android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1 First, I don’t understand how such an error arose: I didn’t ask directly -1 . Probably should have placed the cursor at the beginning before executing the query, but it was not initialized before the query.
Failed to read row 0, column -1 from a CursorWindow which has 1 rows, 1 columns., while the method for obtaining all records works correctly, that is, the table is full. While thinking about the wording of a new question. - GlebgetColumIndex()methods returns -1, which means that columns with this name are not in the database or it is not included in the database selection (not all columns are received). regarding your request - you request only an ID column, without columns containing data. - pavlofff