java - Method to count all rows in my database crashes my app -
i trying count rows in app. call following method app crashes:
public int getdbplacescount() { string countquery = "select * " + table_db_verladestellen_eintrag; sqlitedatabase db = this.getreadabledatabase(); cursor cursor = db.rawquery(countquery, null); cursor.close(); // return count return cursor.getcount(); }
the exception:
caused by: java.lang.illegalstateexception: attempt re-open already-closed object: sqlitequery: select * orte
can tell me did wrong?
you tried cursor count, line above close connection database. should count first, close connection, like:
public int getdbplacescount() { string countquery = "select * " + table_db_verladestellen_eintrag; sqlitedatabase db = this.getreadabledatabase(); cursor cursor = db.rawquery(countquery, null); int count = cursor.getcount(); cursor.close(); // return count return count }
Comments
Post a Comment