关闭游标上的 IllegalStateException
我的问题似乎与以下问题相关:
如何在代码中处理游标上的 IllegalStateException?
违规方法的代码如下:
public boolean isPermanent(String screen_name) {
boolean output = false;
try {
Cursor c = mDb.query(USERS, new String[] {PERMANENT}, NAME + "='" + screen_name + "'", null, null, null, null);
if (c != null && c.getCount() > 0) {
c.moveToFirst();
output = c.getString(0).contentEquals("C");
c.close();
}
}
catch (Exception e) {
Log.e("DBERR", e.getMessage());
}
return output;
}
但是,当抛出异常时,我正在查看有问题的游标,我可以在 Eclipse 中看到以下内容:
this SQLiteCursor (id=830061188288)
mClosed true
mColumnNameMap null
mColumns String[1] (id=830061188608)
mContentObservable ContentObservable (id=830061188456)
mContentResolver null
mCount 0
mCurrentRowID null
mCursorState 0
mDatabase SQLiteDatabase (id=830060407768)
mDataSetObservable DataSetObservable (id=830061188408)
mDriver SQLiteDirectCursorDriver (id=830061143904)
mEditTable "users" (id=830060403008)
mInitialRead 2147483647
mLock null
mMaxRead 2147483647
mNotificationHandler null
mNotifyUri null
mPendingData false
mPos -1
mQuery SQLiteQuery (id=830061143936)
mRowIdColumnIndex -1
mSelfObserver null
mSelfObserverLock Object (id=830061188504)
mSelfObserverRegistered false
mStackTraceElements null
mUpdatedRows HashMap (id=830061144056)
mWindow null
这清楚地表明了游标已关闭,因为它应该是关闭的 - 那么有人知道为什么这应该抛出异常吗?
My question appears to be linked to the following question:
How to Handle in code IllegalStateException on Cursor?
The code for the offending method is as follows:
public boolean isPermanent(String screen_name) {
boolean output = false;
try {
Cursor c = mDb.query(USERS, new String[] {PERMANENT}, NAME + "='" + screen_name + "'", null, null, null, null);
if (c != null && c.getCount() > 0) {
c.moveToFirst();
output = c.getString(0).contentEquals("C");
c.close();
}
}
catch (Exception e) {
Log.e("DBERR", e.getMessage());
}
return output;
}
However, I am looking at the Cursor in question when the exception is thrown, I can see the following in Eclipse:
this SQLiteCursor (id=830061188288)
mClosed true
mColumnNameMap null
mColumns String[1] (id=830061188608)
mContentObservable ContentObservable (id=830061188456)
mContentResolver null
mCount 0
mCurrentRowID null
mCursorState 0
mDatabase SQLiteDatabase (id=830060407768)
mDataSetObservable DataSetObservable (id=830061188408)
mDriver SQLiteDirectCursorDriver (id=830061143904)
mEditTable "users" (id=830060403008)
mInitialRead 2147483647
mLock null
mMaxRead 2147483647
mNotificationHandler null
mNotifyUri null
mPendingData false
mPos -1
mQuery SQLiteQuery (id=830061143936)
mRowIdColumnIndex -1
mSelfObserver null
mSelfObserverLock Object (id=830061188504)
mSelfObserverRegistered false
mStackTraceElements null
mUpdatedRows HashMap (id=830061144056)
mWindow null
And this clearly shows that the state of the Cursor is closed, as it should be - so does anyone have any clues as to why this should be throwing an exception?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
而不是检查 c.getCount() > 0,检查c.moveToNext():
并将关闭移动到finally{}
Instead of checking c.getCount() > 0, check for c.moveToNext():
And move the close to finally{}