Julius,

Judging by the "CursorWindow heap allocation failed" message, your query's result set may be too large. If you only care about getting the IDs, make sure you specify "SELECT _id FROM...", and not "SELECT * FROM...".

Also consider how many rows your query is expected to return. Database queries are cached in RAM, and the default limit in Cursor is to try to allocate up to 2 billion rows. Clearly, that won't work, and the real limit imposed by heap size is smaller still.

Other than that, I usually write cursor loops like this:

Cursor c = ....
try {
int nIndex = c.getColumnIndexOrThrow("column_name");
while (c.moveToNext()) {
long id = c.getLong(nIndex);
.....
}
}
finally {
c.close();
}

-- Kostya

29.07.2011 10:50, Julius Spencer пишет:
The problem occurs on the line with rawQuery(


                ArrayList<Long>  myIds = new ArrayList<Long>();
                        Cursor c = null;
                        try {
                                c = ((MyApplication) 
MyApplication.getApplication()).getDbHelper().getReadableDatabase().rawQuery(queryString,null);
                                if(c.moveToFirst()) {
                                        while(!c.isAfterLast()) {
                                                
myIds.add(c.getLong(c.getColumnIndex(MYID)));
                                                c.moveToNext();
                                        }
                                }
                        } finally {
                                if(null!=c)
                                        c.close();
                        }
                return myIds;

Thanks for any help.


On 29/07/2011, at 6:35 PM, KP wrote:

Code will help.

On Jul 29, 11:16 am, Julius Spencer<[email protected]>  wrote:
Hi,

I have been taking all my database reads off the main UI thread and have come 
across some new problems.

I'm receiving the following error(s):

ERROR/CursorWindow(26242): CursorWindow heap allocation failed

followed by:

ERROR/AndroidRuntime(26242): java.lang.RuntimeException: An error occured while 
executing doInBackground()
ERROR/AndroidRuntime(26242):     at 
android.os.AsyncTask$3.done(AsyncTask.java:200)
ERROR/AndroidRuntime(26242):     at 
java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
ERROR/AndroidRuntime(26242):     at 
java.util.concurrent.FutureTask.setException(FutureTask.java:125)
ERROR/AndroidRuntime(26242):     at 
java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
ERROR/AndroidRuntime(26242):     at 
java.util.concurrent.FutureTask.run(FutureTask.java:138)
ERROR/AndroidRuntime(26242):     at 
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
ERROR/AndroidRuntime(26242):     at 
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
ERROR/AndroidRuntime(26242):     at java.lang.Thread.run(Thread.java:1019)
ERROR/AndroidRuntime(26242): Caused by: java.lang.IllegalStateException: 
Couldn't init cursor window
ERROR/AndroidRuntime(26242):     at 
android.database.CursorWindow.native_init(Native Method)
ERROR/AndroidRuntime(26242):     at 
android.database.CursorWindow.<init>(CursorWindow.java:41)
ERROR/AndroidRuntime(26242):     at 
android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:276)
ERROR/AndroidRuntime(26242):     at 
android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:268)
ERROR/AndroidRuntime(26242):     at 
android.database.AbstractCursor.moveToPosition(AbstractCursor.java:171)
ERROR/AndroidRuntime(26242):     at 
android.database.AbstractCursor.moveToFirst(AbstractCursor.java:248)

I can't seem to find much online about this and don't know what it really means.

Regards,
Julius.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

--
Kostya Vasilyev

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to