首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Android游标非法状态异常崩溃

Android游标非法状态异常崩溃
EN

Stack Overflow用户
提问于 2018-08-03 00:43:48
回答 1查看 159关注 0票数 0

我在一段安卓代码上遇到了一些问题,c.moveToFirst()似乎发生了崩溃。我试图获取一个计数,如果游标结果大于0,则执行该代码,但没有帮助。

我无法在我的应用程序上重现这个错误(我已经尝试了几个场景),但是,通过Google Dev控制台,我看到其他使用我的应用程序的人也收到了这个错误。

提前感谢

崩溃错误:

代码语言:javascript
复制
java.lang.IllegalStateException: 
  at android.database.sqlite.SQLiteConnectionPool.throwIfClosedLocked (SQLiteConnectionPool.java:1198)
  at android.database.sqlite.SQLiteConnectionPool.waitForConnection (SQLiteConnectionPool.java:808)
  at android.database.sqlite.SQLiteConnectionPool.acquireConnection (SQLiteConnectionPool.java:534)
  at android.database.sqlite.SQLiteSession.acquireConnection (SQLiteSession.java:904)
  at android.database.sqlite.SQLiteSession.executeForCursorWindow (SQLiteSession.java:834)
  at android.database.sqlite.SQLiteQuery.fillWindow (SQLiteQuery.java:62)
  at android.database.sqlite.SQLiteCursor.fillWindow (SQLiteCursor.java:152)
  at android.database.sqlite.SQLiteCursor.getCount (SQLiteCursor.java:141)
  at com.andre3.wzlimitdistraction.dao.Dao.read (Dao.java:101)
  at com.andre3.wzlimitdistraction.utils.MonitorService$2.run (MonitorService.java:201)
  at java.util.TimerThread.mainLoop (Timer.java:555)
  at java.util.TimerThread.run (Timer.java:505)

导致它的代码:

代码语言:javascript
复制
    ArrayList<UserApps> arr = new ArrayList<UserApps>();

    int profileId = 0;
    SQLiteDatabase getDb = db.getReadableDatabase();

    if(getDb.isOpen()) {

        String[] columns = {Dbinfo.app.toString(), Dbinfo.app_name.toString(), Dbinfo.start_duration.toString(), Dbinfo.active_duration.toString(), Dbinfo.start_time.toString(), Dbinfo.profile_id.toString()};

        String selection = Dbinfo.app.toString() + " =? and " + Dbinfo.profile_id.toString() + " <=?";
        String[] selectionArgs = {id, String.valueOf(profileId)};
        Cursor c = getDb.query("user_apps", columns, selection, selectionArgs, null, null, null);

        if((c.getCount() > 0) && (c !=null)) {

            if (c.moveToFirst()) {

                do {
                    UserApps form = new UserApps();

                    form.setPkg(c.getString(c.getColumnIndex(Dbinfo.app.toString())));
                    form.setName(c.getString(c.getColumnIndex(Dbinfo.app_name.toString())));

                    arr.add(form);
                } while (c.moveToNext());
            }
        }

        getDb.close();
        c.close();

    }
    return arr;
EN

回答 1

Stack Overflow用户

发布于 2018-08-03 01:16:46

这可能是因为getColumnIndex找不到您指定的列。你可以参考这个Question

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51658583

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档