Could not allocate CursorWindow '/pos-db' of size 2097152 due to error -24

安稳与你 提交于 2021-01-27 05:55:55

问题


Exception Information

cannot open file at line 30176 of [00bb9c9ce4]
 (14) os_unix.c:30176: (24) open(/data/data/c/databases/pos-db-journal) - 
 (14) cannot open file at line 30176 of [00bb9c9ce4]
 (14) os_unix.c:30176: (24) open(/data/data/c/pos-db-journal) - 
 (14) statement aborts at 14: [SELECT T."_id",T."PRINTDATA",T."POSITION",T."DOUBLEFORMAT",
 T."PRINTERMODE",T."INSERTTIME" FROM "PRINT_DATA_ITEM" T] unable to open database file
 E/SQLiteQuery: exception: unable to open database file (code 14); query: SELECT T."_id",T.
 "PRINTDATA",T."POSITION",T."DOUBLEFORMAT",T."PRINTERMODE",T."INSERTTIME" FROM "PRINT_DATA_ITEM" T

part code:

 private PrinterTask(Context context) {
        this.mContext = context;
        helper = new DaoMaster.DevOpenHelper(context, "pos-db", null);
        db = helper.getWritableDatabase();
        mDaoMaster = new DaoMaster(db);
        mDaoSession = mDaoMaster.newSession();
        mPrintDataItemDao = mDaoSession.getPrintDataItemDao();
        mRequestDataItemDao = mDaoSession.getRequestDataItemDao();
    }
//
 public void startPrintThread() {
        dataIsExist = true;
        //
        if (!threadIsRuning) {
            thread = new Thread() {
                @Override
                public void run() {
                    super.run();
                    threadIsRuning = true;
                    List<PrintDataItem> list; 
                    while (dataIsExist) {
                        list = mPrintDataItemDao.loadAll();
                         if (list != null && list.size() > 0) {
                        KLog.d("startPrintThread", String.valueOf(++count) + "  " + String.valueOf(list.size()));
                    }
                    threadIsRuning = false;
                }
            };
            thread.start();
        }

when the count is added to about 600000 ,app will exist without any omen. then logcat output these info.

log output:

(1)Could not create epoll instance. errno=24
(2)CursorWindow(26673): Could not allocate CursorWindow of size 2097152 due to error -24
(3)F/Looper  (26673): Could not create wake pipe.  errno=24
I/qtaguid (20825): Failed write_ctrl(s 0 10051) res=-1 errno=1
 FATAL EXCEPTION: Thread-118`enter code here`

what i can do so solve this problem? I will appreciate it!


回答1:


These code is Ok. I find other code load these Exception. I use intentservice and AlarmManager to make a cyclic service. I give up the AlarmManager. Then change code like this: It works. Exception no longer appear.

new Thread(new Runnable() {
        @Override
        public void run() {
            mRequestDataItem = DBHelper.getInstance(getApplicationContext()).getTopFailedNetRequestInDataBase();
            while (isRunning) {
                CommonUtilLog.d("reRequestTask Loop", String.valueOf(countLoop++));
                if (!isPosting) {
                    if (reRequestTask == null) {
                        if (mRequestDataItem != null) {
                            CommonUtilLog.d("reRequestTask", String.valueOf(count++));
                            reRequestTask = new ReRequestTask(mRequestDataItem);
                        }
                    }
                }
                try {
                    Thread.sleep(CommonConstant.THREAD_SLEEP_RETRY_REQUEST_SERVICE);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                mRequestDataItem = DBHelper.getInstance(getApplicationContext()).getTopFailedNetRequestInDataBase();
            }
        }
    }).start();

the way to find the problem: 来自这篇博客的博主:http://ju.outofmemory.cn/entry/247095 “差异法”,逐步注释代码,找出出错的真凶.




回答2:


"Could not allocate CursorWindow of size 2097152 due to error ...."
occurs when a cursor is not closed and is called in loop.
Cursor error is not shown to avoid data leak logging.
To know error in my code, I added these lines.
when activity opens, and it exactly pointed to the line that was causing the error.

        if (BuildConfig.DEBUG) {
            StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
                    .detectLeakedSqlLiteObjects()
                    .detectLeakedClosableObjects()
                    .penaltyLog()
                    .penaltyDeath()
                    .build());
        }


来源:https://stackoverflow.com/questions/36300821/could-not-allocate-cursorwindow-pos-db-of-size-2097152-due-to-error-24

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