在android 数据库开发中碰到了这么一个错误:
E/CursorWindow: Failed to read row 0, column -1 from a CursorWindow which has 1 rows, 9 columns.
E/com.ishow.app.manager.AppManager: java.lang.RuntimeException: Unable to create service com.ishow.app.lbs.LBSService: java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3145)
at android.app.ActivityThread.access$1800(ActivityThread.java:185)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1655)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5847)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1010)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
Caused by: java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
at android.database.CursorWindow.nativeGetString(Native Method)
at android.database.CursorWindow.getString(CursorWindow.java:438)
at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:66)
at com.ishow.app.dao.impl.AccountDaoImpl.getAccount(AccountDaoImpl.java:87)
at com.ishow.app.dao.impl.AccountDaoImpl.getCurrentAccount(AccountDaoImpl.java:67)
at com.ishow.app.protocol.BaseProtocol.<init>(BaseProtocol.java:29)
at com.ishow.app.protocol.AbstractProtocol.<init>(AbstractProtocol.java:0)
at com.ishow.app.protocol.AppRecordProtocol.<init>(AppRecordProtocol.java:0)
at com.ishow.app.api.AppRecordHandler.post(AppRecordHandler.java:63)
at com.ishow.app.api.AppRecordHandler.post(AppRecordHandler.java:59)
at com.ishow.app.lbs.LBSService.onCreate(LBSService.java:57)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3135)
at android.app.ActivityThread.access$1800(ActivityThread.java:185)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1655)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5847)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1010)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
,version=2.2.5.14,exception time=2017-03-22 16:08:49
I/Process: Sending signal. PID: 19041 SIG: 9
E/CursorWindow: Failed to read row 0, column -1 from a CursorWindow which has 1 rows, 9 columns.
E/com.ishow.app.manager.AppManager: java.lang.RuntimeException: Unable to create service com.ishow.app.lbs.LBSService: java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3145)
at android.app.ActivityThread.access$1800(ActivityThread.java:185)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1655)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5847)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1010)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
Caused by: java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
at android.database.CursorWindow.nativeGetString(Native Method)
at android.database.CursorWindow.getString(CursorWindow.java:438)
at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:66)
at com.ishow.app.dao.impl.AccountDaoImpl.getAccount(AccountDaoImpl.java:87)
at com.ishow.app.dao.impl.AccountDaoImpl.getCurrentAccount(AccountDaoImpl.java:67)
at com.ishow.app.protocol.BaseProtocol.<init>(BaseProtocol.java:29)
at com.ishow.app.protocol.AbstractProtocol.<init>(AbstractProtocol.java:0)
at com.ishow.app.protocol.AppRecordProtocol.<init>(AppRecordProtocol.java:0)
at com.ishow.app.api.AppRecordHandler.post(AppRecordHandler.java:63)
at com.ishow.app.api.AppRecordHandler.post(AppRecordHandler.java:59)
at com.ishow.app.lbs.LBSService.onCreate(LBSService.java:57)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3135)
at android.app.ActivityThread.access$1800(ActivityThread.java:185)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1655)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5847)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1010)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
,version=2.2.5.14,exception time=2017-03-22 16:08:49
I/Process: Sending signal. PID: 19041 SIG: 9
Disconnected from the target VM, address: 'localhost:8611', transport: 'socket'
发生错误的主要原因是:
因为需求的变动,要在原有的数据库中新增一个字段,新增了字段后所有的工作都准备得差不多了,但忽略了一个地方,就是数据库版本还没有升级,运行后先读取数据库,没有新增的字段,进而导致以上异常的发生
解决方法:
将数据库版本升级后,在数据库版本更新方法中新增该字段,问题解决