光标索引出界异常的 [英] Cursor Index Out of Bounds Exception
问题描述
在试图对我的数据库执行查询,我得到这个例外。但是,文档指出该方法 SQLiteDatabase.query(...)
的回报,一个Cursor对象,它是定位在第一项之前,这是我除preT意味着光标在返回的行的开始。如果我添加了 Cursor.moveToFirst()
光标访问数据之前,我没有得到任何的异常。到底是怎么回事?我是否需要试图让数据之前,总是称之为moveToFirst?该文件说,这种方法,将光标移动到第一行。
光标C = db.query(TABLENAME,NULL,NULL,NULL,NULL,NULL,NULL);
Log.d(TAG,+ c.getInt(c.getColumnIndex(_ ID)));
查询后,您需要调用下一个()
或 moveToFirst()
。光标懒加载,调用光标被加载到内存这些方法之后。您可以决定什么时候做。
In attempting to execute a query on my database, I get this exception. However, the documentation states that the method SQLiteDatabase.query(...)
returns, "A Cursor object, which is positioned before the first entry," which I interpret to mean that the Cursor is at the start of the rows returned. If I add the Cursor.moveToFirst()
before accessing data in the Cursor, I get no exception. What is going on? Do I need to always call "moveToFirst" before trying to get data? The documentation says this method, "moves the cursor to the first row."
Cursor c = db.query(TABLENAME, null, null, null, null, null, null);
Log.d("TAG",""+c.getInt(c.getColumnIndex("_id")));
After query you need to call next()
or moveToFirst()
. Cursors are lazy loaded, after calling these methods cursor is loaded into memory. You can decide when to do it.
这篇关于光标索引出界异常的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!