开发者

Sqlite Out of Memory when preparing update statement

开发者 https://www.devze.com 2023-02-24 06:44 出处:网络
I have one problem with my application. I create a one AsyncTask for downloading list of files from server . When all the files are download after that i update the database. But when i called the up

I have one problem with my application.

I create a one AsyncTask for downloading list of files from server . When all the files are download after that i update the database. But when i called the update query its give me the below error.

Failure 21 (out of memory) on 0x0 when preparing update

Can any one tell me why this error occurs ?

Sample Code

public void setStatus(int index)
{
    try
    {
        db.OpenDatabase();
        db.updateStatus(id.get(index), 1);
        db.closeDatabase();
    }
    catch(E开发者_如何转开发xception e)
    {
        e.printStackTrace();
    }
}

Above function called from the AsyncTask ....

public void updateStatus(int id,int status)
{
    try
    {
        db.execSQL("update sample set status =" + status + " where id = " + id);
    }
    catch(Exception e){e.printStackTrace();}
}


This may not be related to the database pe se, but rather to the fact that the memory (heap) is almost full and opening the database completely fills it up.

Remember that most handsets have 48MB of heap or even less.


Sometime while working I also got the same error.

I used this link

"Failure 21 (out of memory)" when performing some SQLite operations

It said that this error occurs when you try to work on a closed DB. I looked back into my code and found that I was also doing the same. Got it working afterwards

I think you are also trying to work on a closed DB.


Have you tried to use the update() method instead of execSQL()?

public void updateStatus(int id,int status)
{
    try
    {
         ContentValues values = new ContentValues();
         values.put("status", status);
         db.update ("sample", values, "id = ?", new String[]{Integer.toString(id)});
    }
    catch(Exception e){e.printStackTrace();}
}


I has "out of memory" error (21) when I try to call sqlite3_prepare() with a NULL pointer to database handle. Check if your handle is valid and the database is opened.

0

精彩评论

暂无评论...
验证码 换一张
取 消