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

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -