Please check my code.. getCount() method is not returning the number of rows in the table.. also it gives runtime exceptions and on opening the app it gives alert message "Unfortunately app stopped working"
public int getTotalRows() {
String countQuery = "SELECT * FROM " + TABLE_OOPBASICS;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(countQuery, null);
cursor.close();
return cursor.getCount();
}
The method should return number of rows in the table.
you're closing the Cursor..that's why.
do the cursor.close(); after the cursor.getCount()
public int getTotalRows() {
String countQuery = "SELECT * FROM " + TABLE_OOPBASICS;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(countQuery, null);
if (cursor != null) {
count = cursor.getCount();
cursor.close();
}
return count;
}