无法分配CursorWindow' / pos-db'尺寸为2097152,由于错误-24

时间:2016-03-30 05:58:34

标签: android greendao

异常信息

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

部分代码:

 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();
        }

当计数被添加到大约600000时,app将存在而没有任何预兆。然后logcat输出这些信息。

日志输出:

(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`

我能做什么才能解决这个问题?我会很感激的!

2 个答案:

答案 0 :(得分:1)

这些代码没问题。我发现其他代码加载这些异常。 我使用intentservice和AlarmManager来进行循环服务。 我放弃了AlarmManager。然后像这样更改代码: 有用。不再出现异常。

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();

找到问题的方法: 来自这篇博客的博主:http://ju.outofmemory.cn/entry/247095 “差异法”,逐步注释代码,找出出错的真凶。

答案 1 :(得分:1)

“由于错误,无法分配大小为 2097152 的 CursorWindow ....”
当游标未关闭并在循环中调用时发生。
不显示光标错误以避免数据泄漏记录。
为了知道我的代码中的错误,我添加了这些行。
当活动打开时,它正好指向导致错误的行。

$pip install pycups
Collecting pycups
    Using cached pycups-2.0.1.tar.gz (62 kB)
Building wheels for collected packages: pycups
    Building wheel for pycups (setup.py) ... error
    ERROR: Command errored out with exit status 1:
    command: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip- 
    install-_itolwzg/pycups_229a8ad4200041038747d41d5862ab4c/setup.py'"'"'; __file__='"'"'/tmp/pip- 
    install-_itolwzg/pycups_229a8ad4200041038747d41d5862ab4c/setup.py'"'"';f=getattr(tokenize, 
    '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', 
    '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel- 
    29ml6iuu
       cwd: /tmp/pip-install-_itolwzg/pycups_229a8ad4200041038747d41d5862ab4c/
    Complete output (165 lines):
    running bdist_wheel
    running build
    running build_ext
    building 'cups' extension
    creating build
    creating build/temp.linux-x86_64-3.6
    gcc -pthread -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -DVERSION="2.0.1" - 
    I/usr/local/include/python3.6m -c cupsmodule.c -o build/temp.linux-x86_64-3.6/cupsmodule.o
    cupsmodule.c: In function 'cups_enumDests':
    cupsmodule.c:422: warning: implicit declaration of function 'cupsEnumDests'
    cupsmodule.c: In function 'cups_connectDest':
    cupsmodule.c:501: warning: implicit declaration of function 'cupsConnectDest'
    cupsmodule.c:508: warning: assignment makes pointer from integer without a cast
    cupsmodule.c: In function 'PyInit_cups':
    cupsmodule.c:919: error: 'HTTP_STATUS_ERROR' undeclared (first use in this function)
    cupsmodule.c:919: error: (Each undeclared identifier is reported only once
    cupsmodule.c:919: error: for each function it appears in.)
    .....
    error: command 'gcc' failed with exit status 1
    ----------------------------------------
    ERROR: Failed building wheel for pycups
    Running setup.py clean for pycups