attempt to reopen an already-closed object: sqlitequery

一笑奈何 提交于 2019-12-05 08:07:38

You should post a logcat if you are getting an error. It helps to see which line is causing your problem.

From the Android docs.

close()

Closes the Cursor, releasing all of its resources and making it completely invalid.

Your call to mcursor.getCount() after you have closed it is likely causing the error

Maybe try something like this.

int count = mcursor.getCount();
mcursor.close();

// return count
return count ;

I'm assuming here that pullAllDB is your database object which contains the code doing the queries. In that case, before the line, List<Beacon> beaconsShown = pullAllDB.getAllBeacons();, you should do something like pullAllDB.open(); and do pullAllDB.close(); after you are done running queries.

So all in all, your function would look like..

try {
    //open the database class here
    pullAllDB.open();

    List<Beacon> beaconsShown = pullAllDB.getAllBeacons();
    for (final Beacon bn : beaconsShown) {
        try {
            int messageCount = pullAllDB.getMessageCount();
            Log.d("Message", messageCount + " Messages Found");
            if (messageCount > 0) {
                //Do Something
            } else {
                // Do Nothing
            }
        } 
        catch (Exception e) {
            e.getStackTrace();
            Log.e("Message", e.getMessage());
        }

    //close the database here
    pullAllDB.close();
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!