I would like to print the following information to the logcat window in Android:
• The database version number (using db.getVersion() for the version number). • The number of columns in the cursor. • The name of the columns in the cursor. • The number of results in the cursor • Each row of results in the cursor
I have created the following class at the end of my app to accomplished this:
public void printCursor(Cursor c, int version) {
int dbVersion = version;
int numberCursorColumns = c.getColumnCount();
String[] nameCursorColumns = c.getColumnNames();
int numberCursorResults = c.getCount();
List<Message> cursorRowValuesList = new ArrayList<>();
String cursorRowValues;
c.moveToFirst();
if (c.moveToFirst()) {
int sendColIndex = c.getColumnIndex(MyOpener.COL_TEXT);
int typeColIndex = c.getColumnIndex(MyOpener.MESSAGE_TYPE);
int idColIndex = c.getColumnIndex(MyOpener.COL_ID);
String send = c.getString(sendColIndex);
int type = c.getInt(typeColIndex);
long id = c.getLong(idColIndex);
cursorRowValuesList.add(new Message(send, type, id));
}
cursorRowValues = TextUtils.join(",", cursorRowValuesList);
Log.i("DATABASE VERSION", Integer.toString(dbVersion));
Log.i("NUMBER OF COLUMNS", Integer.toString(numberCursorColumns));
Log.i("COLUMN NAMES", Arrays.toString(nameCursorColumns));
Log.i("NUMBER OF RESULTS", Integer.toString(numberCursorResults));
Log.i("ROW VALUES", cursorRowValues);
}
All of the printouts work, except for the final one, ROW VALUES, which is supposed to print each row of results in the cursor. This is what prints in the logcat when I run the app:
02-14 14:52:35.222 5969-5969/com.example.androidlabs I/DATABASE VERSION: 1
02-14 14:52:35.222 5969-5969/com.example.androidlabs I/NUMBER OF COLUMNS: 3
02-14 14:52:35.222 5969-5969/com.example.androidlabs I/COLUMN NAMES: [_id, TEXT, TYPE]
02-14 14:52:35.222 5969-5969/com.example.androidlabs I/NUMBER OF RESULTS: 3
02-14 14:52:35.222 5969-5969/com.example.androidlabs I/ROW VALUES:com.example.androidlabs.Message@55b3428
Why am I getting that message for ROW VALUES?