我在 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 上崩溃了,我已经在答案中添加了代码。
非常感谢