gpt4 book ai didi

安卓java.lang.IllegalStateException : Couldn't init cursor window

转载 作者:搜寻专家 更新时间:2023-11-01 07:34:52 25 4
gpt4 key购买 nike

我在 google play 崩溃报告中有这个错误,不知道如何解决:

java.lang.IllegalStateException: Couldn't init cursor window
at android.database.CursorWindow.native_init(Native Method)
at android.database.CursorWindow.<init>(CursorWindow.java:41)
at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:276)
at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:268)
at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:171)
at android.database.AbstractCursor.moveToFirst(AbstractCursor.java:248)
at com.jim2.UpdateService.restaureNotifications(UpdateService.java:274)
at com.jim2.helpers.Globals.updateWidgets(Globals.java:1011)
at com.jim2.helpers.Globals.onReceive(Globals.java:746)
at com.jim2.UpdateService$5.onSignalStrengthsChanged(UpdateService.java:747)
at android.telephony.PhoneStateListener$2.handleMessage(PhoneStateListener.java:387)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3693)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
at dalvik.system.NativeStart.main(Native Method)

这是我崩溃的代码:

    DataBaseHelper d = new DataBaseHelper(context);
Cursor c = d.getNotifications(false);
SharedPreferences preferences;
String ns = Context.NOTIFICATION_SERVICE;

NotificationManager mNotificationManager = (NotificationManager)context.getSystemService(ns);

CharSequence tickerText = "";

if(c!=null && c.moveToFirst()){ // CRASH HERE :(

do{
....
while(c.moveToNext());
if(c!=null && !c.isClosed()) {
c.close();c = null;
}
}
d.close();

这里是从 getNotifications 获取光标的代码:

public Cursor getNotifications(boolean all) {
//removeAllNotifications();
Cursor c;
String fields[] = new String[] { "id", "ordre", "is_active"};
String where = "is_active = 1";
if(all)where = "";
c = myDataBase.query(TABLE, fields, where, null, null, null, "ordre");

return c;
}

我的问题是我无法重现崩溃,因此很难修复,因为我的设备都可以正常工作。

已经看到这篇文章 Android: Couldn't init Cursor Window但我后来在 moveToFirst 上崩溃了,我已经在答案中添加了代码。

非常感谢

最佳答案

此异常由 native 代码抛出。 (引用this)

主要是因为没有为正在创建的新游标分配内存。所以我的猜测是您获取的数据有时会太多(内存中将近超过 1M),或者您在打开大量游标而不关闭它们直到内存不足以分配新缓冲区。

  1. 检查代码并确保在 finally 子句中关闭所有游标。
  2. 如果从数据库中获取的数据可能太大,请将它们分成不同的 block (例如拉取更多内容)。

如果这有帮助,请告诉我。

关于安卓java.lang.IllegalStateException : Couldn't init cursor window,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12928708/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com