0

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(Exception 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();}
}
Chirag
  • 56,621
  • 29
  • 151
  • 198

4 Answers4

1

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.

Heiko Rupp
  • 30,426
  • 13
  • 82
  • 119
  • You mentioned downloading a "list of files". If you do any complex-ish parsing of that list of files that may be enough to fill your heap with temporaries that aren't garbage collected yet. – Torp Apr 11 '11 at 13:22
1

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.

Community
  • 1
  • 1
JaydeepW
  • 3,237
  • 1
  • 25
  • 27
0

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.

Eddy
  • 1
  • 2
0

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();}
}
Flo
  • 27,355
  • 15
  • 87
  • 125