android – 光标窗口分配2048 kb失败. #Open Cursors = 1(此proc = 1打开的#游标)

android – 光标窗口分配2048 kb失败. #Open Cursors = 1(此proc = 1打开的#游标),第1张

概述我正在制作一个使用数据库的Kiosk应用程序.该应用程序一直在前台运行.该应用程序有许多使用一个共享DataBaseHelper实例的线程.该应用程序完美无缺,但大多数时间在5或6小时后,我遇到这些异常,然后应用程序崩溃: E/DataBaseHelper﹕ Cursor window allocation of 2048 kb failed. # Open Cursors=1 (# cursor 我正在制作一个使用数据库的Kiosk应用程序.该应用程序一直在前台运行.该应用程序有许多使用一个共享DataBaseHelper实例的线程.该应用程序完美无缺,但大多数时间在5或6小时后,我遇到这些异常,然后应用程序崩溃:

E/DataBaseHelper﹕ Cursor window allocation of 2048 kb Failed. # Open
Cursors=1 (# cursors opened by this proc=1)

E/CursorWindow﹕ Could not allocate CursorWindow
‘/data/user/0/com.kios.frm/databases/YadProjectDB.db’ of
size 2097152 due to error -24.

E/sqliteLog﹕ (14) cannot open file at line 30192 of [00bb9c9ce4]

E/sqliteLog﹕ (14) statement aborts at 16: [SELECT number FROM sms
liMIT 5] unable to open database file

E/sqlitequery﹕ exception: unable to open database file (code 14);
query: SELECT number FROM sms liMIT 5

E/sqliteLog﹕ (14) os_unix.c:30192: (24)
open(/data/user/0/com.kiosk.frm/databases/YadProjectDB.db-journal)-

我正确关闭了光标,但仍然获得了这些异常.那些例外是什么?这些例外的原因是什么?

主要活动

private DataBaseHelper db = null; // Global

MainActivity onCreate方法:

db = new DataBaseHelper(this);new Thread(new Runnable() {@OverrIDepublic voID run() {    while (threadRunningFlag) {    Cursor result = null;    try {        result = db.getData("SELECT " + DataBaseHelper.SMS_ColUMN_PHONE_NUMBER  + " FROM " + DataBaseHelper.SMS_table_name + " liMIT 5");        if (result != null && result.getCount() > 0) {            while (!result.isAfterLast()) {                String phoneNumber = result.getString(result.getColumnIndex(DataBaseHelper.SMS_ColUMN_PHONE_NUMBER));                // ...                result.movetoNext();            }        }    }catch (Exception e) {        Log.e(TAG,"err->" + e.getLocalizedMessage());    }finally {        if (result != null) {            result.close();            result = null;        }    }        try {            Thread.sleep(1000);        } catch (InterruptedException e) {            Log.e(TAG,e.getMessage());        }    }}}).start();

DataBaseHelper类:

public class DataBaseHelper extends sqliteOpenHelper {    private static final int DATABASE_VERSION = 1;    public static final String DATABASE_name = "YadProjectDB.db";    public static final String SMS_table_name = "sms";    public static final String SMS_ColUMN_PHONE_NUMBER = "number";    public static final String SMS_ColUMN_SMS_TEXT = "message";    public static final String BLACK_List_table_name = "blackList";    public static final String BLACK_List_ColUMN_ID = "ID";    public static final String BLACK_List_ColUMN_PHONE_NUMBER = "number";    private final String TAG = "DataBaseHelper";    public DataBaseHelper(Context context) {        super(context,DATABASE_name,null,DATABASE_VERSION);    }    @OverrIDe    public voID onCreate( sqliteDatabase db ) {        String command = "CREATE table "                + SMS_table_name                + "("                + SMS_ColUMN_PHONE_NUMBER + " TEXT,"                + SMS_ColUMN_SMS_TEXT + " TEXT,"                + ")";        try {            db.execsql(command);        }catch (Exception e) {            Log.e(TAG,"err->" + e.getMessage());        }        command = "CREATE table "                + BLACK_List_table_name                + "("                + BLACK_List_ColUMN_PHONE_NUMBER + " TEXT,"err->" +  e.getMessage());        }    }    public boolean insertToSms(String number,String message,String filename,Integer uploadFlag,Integer blackList,Integer pictureFlag)    {        final sqliteDatabase db = this.getWritableDatabase();        ContentValues contentValues = new ContentValues();        contentValues.put(SMS_ColUMN_PHONE_NUMBER,number);        contentValues.put(SMS_ColUMN_SMS_TEXT,message);        try {            db.insert(SMS_table_name,contentValues);            return true;        }catch (Exception e) {            Log.e(TAG,"err->" + e.getMessage());            return false;        }    }    public Cursor getData(String query){        final sqliteDatabase db = getReadableDatabase();        Cursor res = null;        try {            res = db.rawquery(query,null);            res.movetoFirst();            return res;        }catch (Exception e) {            Log.e(TAG,"err->" + e.getMessage());            if (res != null) {                res.close();                res = null;            }        }        return null;    }}
解决方法 这与 SQLite Android Database Cursor window allocation of 2048 kb failed看起来相同

你的错误说:“打开游标

上述问题的答案解释了:

Most often the cause for this error are non closed cursors. Make sure
you close all cursors after using them (even in the case of an error).

Cursor cursor = null;try {    cursor = db.query(...    // do some work with the cursor here.} finally {    // this gets called even if there is an exception somewhere above    if(cursor != null)        cursor.close();}
总结

以上是内存溢出为你收集整理的android – 光标窗口分配2048 kb失败. #Open Cursors = 1(此proc = 1打开的#游标)全部内容,希望文章能够帮你解决android – 光标窗口分配2048 kb失败. #Open Cursors = 1(此proc = 1打开的#游标)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1130834.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存