Tuesday, 15 February 2011

java - Android CursorWindowAllocationException -



java - Android CursorWindowAllocationException -

i'm getting error :

e/androidruntime(8223): caused by: android.database.cursorwindowallocationexception: cursor window allocation of 2048 kb failed. # open cursors=940 (# cursors opened proc=940)

i know because i'm using cursor in wrong way or not closing @ right time. think because i'm filling same cursor without closing/emptying it?

public static void nextalarmtxt(){ int dan = c.get(calendar.day_of_week); long trenutnovrijeme = c.gettimeinmillis(); long bazavrijeme; long pamti = 0; string danstring = dani(dan); cursor cursordan = databasemanager.getalldataday(danstring); cursordan.movetofirst(); if (!cursordan.isafterlast()) { { bazavrijeme = cursordan.getint(2); if (trenutnovrijeme<bazavrijeme) { if (pamti==0) { pamti = bazavrijeme; } if (pamti>0) { if (pamti > bazavrijeme) { pamti = bazavrijeme; } } } if (trenutnovrijeme > bazavrijeme) { dan = dan+1; dani(dan); cursordan = databasemanager.getalldataday(danstring); } } while (cursordan.movetonext()); } cursordan.close(); text1.settext(new stringbuilder("sljedeći : " ).append(pamti).tostring()); } public static string dani(int dan){ string danstring = null; if (dan==1) { danstring = "nedjelja"; } else if (dan==2) { danstring = "ponedjeljak"; } else if (dan==3) { danstring = "utorak"; } else if (dan==4) { danstring = "srijeda"; } else if (dan==5) { danstring = "Četvrtak"; } else if (dan==6) { danstring = "petak"; } else if (dan==7) { danstring = "subota"; } homecoming danstring; }

cursor opened :

cursor cursordan = databasemanager.getalldataday(danstring);

after iterate through cursor,

do { ... if (trenutnovrijeme > bazavrijeme) { dan = dan+1; dani(dan); cursordan = databasemanager.getalldataday(danstring); } .... } while (cursordan.movetonext());

now, in iteration loop, overwrite existing cursor new one, leaves existing 1 open. not sure trying achieve, should not nesting cursor iteration way , if that, should in right sequece.

close existing cursor retrieve new cursor move new cursor first item cursor.movetofirst()

java android cursor

No comments:

Post a Comment