如何修复(android.database.CursorWindowAllocationException)崩溃

时间:2014-07-22 00:57:24

标签: android sqlite parse-platform

在Parse中的本地数据存储功能可用之前,我曾经拥有自己的本地数据库以供离线应用使用。我认为一切顺利,直到我决定将一个主屏幕小部件添加到我的应用程序,其服务和从该本地数据库提供的列表视图。过了一段时间我开始从用户那里得到一些错误(光标分配,#Opened Cursors),我认为这是次要的,可能是由于手机问题等,但后来我自己开始体验它们......我试图解决它们在SO中建议的各种可能的方式,各种类型的解决方案,试图关闭指向数据库的所有内容,尝试/捕获东西等,什么都没有。所以几个月之后,我放弃了,并且对自己说,就是它,将使用Parse的Local DataStore,我相信它比我的sqlite实现更好。

这可能是一个月前,我认为事情已经解决,但今天出现了这个错误,即使没有使用该应用程序也会出现。我停止了应用程序和服务,重新启动/关闭电源,但是当手机解锁时它仍然存在,因为今天下午无法打开应用程序,它是不变的。

我不知道如何修复它,这是一个4个月的噩梦。希望能伸出援助之手,谢谢。

07-21 19:01:29.360: E/CursorWindow(17106): Could not allocate CursorWindow '/data/data/com.xoaquin.r07d/databases/ParseOfflineStore' of size 2097152 due to error -12.
07-21 19:01:29.470: E/CursorWindow(17106): Could not allocate CursorWindow '/data/data/com.xoaquin.r07d/databases/ParseOfflineStore' of size 2097152 due to error -12.
07-21 19:01:29.480: E/AndroidRuntime(17106): FATAL EXCEPTION: main
07-21 19:01:29.480: E/AndroidRuntime(17106): Process: com.xoaquin.r07d, PID: 17106
07-21 19:01:29.480: E/AndroidRuntime(17106): java.lang.RuntimeException: Unable to create application com.xoaquin.r07d.DefaultApplication: android.database.CursorWindowAllocationException: Cursor window allocation of 2048 kb failed. # Open Cursors=582 (# cursors opened by this proc=582)
07-21 19:01:29.480: E/AndroidRuntime(17106):    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4471)
07-21 19:01:29.480: E/AndroidRuntime(17106):    at android.app.ActivityThread.access$1500(ActivityThread.java:145)
07-21 19:01:29.480: E/AndroidRuntime(17106):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1266)
07-21 19:01:29.480: E/AndroidRuntime(17106):    at android.os.Handler.dispatchMessage(Handler.java:102)
07-21 19:01:29.480: E/AndroidRuntime(17106):    at android.os.Looper.loop(Looper.java:136)
07-21 19:01:29.480: E/AndroidRuntime(17106):    at android.app.ActivityThread.main(ActivityThread.java:5141)
07-21 19:01:29.480: E/AndroidRuntime(17106):    at java.lang.reflect.Method.invokeNative(Native Method)
07-21 19:01:29.480: E/AndroidRuntime(17106):    at java.lang.reflect.Method.invoke(Method.java:515)
07-21 19:01:29.480: E/AndroidRuntime(17106):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
07-21 19:01:29.480: E/AndroidRuntime(17106):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:611)
07-21 19:01:29.480: E/AndroidRuntime(17106):    at dalvik.system.NativeStart.main(Native Method)
07-21 19:01:29.480: E/AndroidRuntime(17106): Caused by: android.database.CursorWindowAllocationException: Cursor window allocation of 2048 kb failed. # Open Cursors=582 (# cursors opened by this proc=582)
07-21 19:01:29.480: E/AndroidRuntime(17106):    at android.database.CursorWindow.<init>(CursorWindow.java:104)
07-21 19:01:29.480: E/AndroidRuntime(17106):    at android.database.AbstractWindowedCursor.clearOrCreateWindow(AbstractWindowedCursor.java:198)
07-21 19:01:29.480: E/AndroidRuntime(17106):    at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:139)
07-21 19:01:29.480: E/AndroidRuntime(17106):    at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:133)
07-21 19:01:29.480: E/AndroidRuntime(17106):    at com.parse.ParseSQLiteDatabase$12.then(ParseSQLiteDatabase.java:214)
07-21 19:01:29.480: E/AndroidRuntime(17106):    at com.parse.ParseSQLiteDatabase$12.then(ParseSQLiteDatabase.java:205)
07-21 19:01:29.480: E/AndroidRuntime(17106):    at com.parse.Task$11.run(Task.java:481)
07-21 19:01:29.480: E/AndroidRuntime(17106):    at com.parse.Task$ImmediateExecutor.execute(Task.java:673)
07-21 19:01:29.480: E/AndroidRuntime(17106):    at com.parse.Task.completeAfterTask(Task.java:477)
07-21 19:01:29.480: E/AndroidRuntime(17106):    at com.parse.Task.continueWithTask(Task.java:353)
07-21 19:01:29.480: E/AndroidRuntime(17106):    at com.parse.Task.continueWithTask(Task.java:364)
07-21 19:01:29.480: E/AndroidRuntime(17106):    at com.parse.Task$9.then(Task.java:410)
07-21 19:01:29.480: E/AndroidRuntime(17106):    at com.parse.Task$9.then(Task.java:402)
07-21 19:01:29.480: E/AndroidRuntime(17106):    at com.parse.Task$11.run(Task.java:481)
07-21 19:01:29.480: E/AndroidRuntime(17106):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
07-21 19:01:29.480: E/AndroidRuntime(17106):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
07-21 19:01:29.480: E/AndroidRuntime(17106):    at java.lang.Thread.run(Thread.java:841)
07-21 19:01:29.551: E/CursorWindow(17106): Could not allocate CursorWindow '/data/data/com.xoaquin.r07d/databases/ParseOfflineStore' of size 2097152 due to error -12.
07-21 19:01:38.119: E/WindowManager(674): Starting window AppWindowToken{4312f298 token=Token{42bd2558 ActivityRecord{42538230 u0 com.xoaquin.r07d/.MainActivity t57}}} timed out

以下是我在使用自己的sqlite实现时遇到的错误,然后再更改为Parse Local Datastore:

java.lang.RuntimeException: Unable to create application com.xoaquin.r07d.DefaultApplication: android.database.CursorWindowAllocationException: Cursor window allocation of 2048 kb failed. # Open Cursors=762 (# cursors opened by this proc=762)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4428)
at android.app.ActivityThread.access$1500(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1270)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5102)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.database.CursorWindowAllocationException: Cursor window allocation of 2048 kb failed. # Open Cursors=762 (# cursors opened by this proc=762)
at android.database.CursorWindow.<init>(CursorWindow.java:104)
at android.database.AbstractWindowedCursor.clearOrCreateWindow(AbstractWindowedCursor.java:198)
at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:139)
at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:133)
at com.parse.ParseSQLiteDatabase$12.then(ParseSQLiteDatabase.java:214)
at com.parse.ParseSQLiteDatabase$12.then(ParseSQLiteDatabase.java:205)
at com.parse.Task$11.run(Task.java:481)
at com.parse.Task$ImmediateExecutor.execute(Task.java:673)
at com.parse.Task.completeAfterTask(Task.java:477)
at com.parse.Task.continueWithTask(Task.java:353)
at com.parse.Task.continueWithTask(Task.java:364)
at com.parse.Task$9.then(Task.java:410)
at com.parse.Task$9.then(Task.java:402)
at com.parse.Task$11.run(Task.java:481)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)

在我的应用程序类的代码下面,是我自己代码的唯一类在错误中提到(可能存在不同的错误):

public class DefaultApplication extends Application{ 


    private static Context context; 

    @Override
    public void onCreate() {
        super.onCreate();

        String manufacturer = Build.MANUFACTURER;
        String brand        = Build.BRAND;
        String product      = Build.PRODUCT;
        String model        = Build.MODEL;

        Parse.enableLocalDatastore(this);
        Parse.initialize(this, "KfBj6ivkLAaYqo", "ePZ6T7RmvGGw3"); 




            PushService.setDefaultPushCallback(this, MainActivity.class);

            ParseFacebookUtils.initialize("75589");

            PushService.subscribe(this, "todos", MainActivity.class);

            ParseUser cu = ParseUser.getCurrentUser(); 
            if(cu!=null){

            String nombretablausuario=cu.getUsername();  

            if(nombretablausuario!=null){

                if (nombretablausuario.contains("\\.")||nombretablausuario.contains("@")){
                          nombretablausuario=nombretablausuario.replaceAll("\\.", "");
                          nombretablausuario=nombretablausuario.replaceAll("@", "");    
                      }
            PushService.subscribe(this, nombretablausuario,MainActivity.class); 

            }

            ParseInstallation installation = ParseInstallation.getCurrentInstallation();
            installation.put("actualuser",cu.getUsername());
            installation.put("manufacturer", manufacturer);
            installation.put("brand", brand);
            installation.put("product", product);
            installation.put("model", model);
            installation.saveEventually();

            }

            String locale = getResources().getConfiguration().locale.getDisplayName();

            if(locale.contains("espa\u00F1ol")){ 

                PushService.subscribe(this, "jalert", JalertActivity.class);
                PushService.unsubscribe(this, "jalerting");
            }else{
                PushService.subscribe(this, "jalerting", JalertActivity.class);
                PushService.unsubscribe(this, "jalert");
            }

             context=getApplicationContext();

    }


    public static Context getCustomAppContext(){ 
      return context;
    }


}

2 个答案:

答案 0 :(得分:1)

我将回答我自己的问题:没有解决方案,Parse团队也没有回应。

我现在正在使用 SharedPreferences 文件处理本地数据以提供小部件。任何使用Parse Local Datastore都会随着时间的推移产生游标错误。

希望这有助于在从主屏幕小部件和/或服务查询本地sqlite数据库时遇到相同问题的人。

答案 1 :(得分:0)

看起来你可能不需要打开许多游标(其中582个)。如果您明确创建游标,请检查是否在不再需要游标时关闭游标。