光标索引出界异常的光标、索引、异常

由网友(一切为零i)分享简介:在试图对我的数据库执行查询,我得到这个例外。但是,文档指出该方法 SQLiteDatabase.query(...)的回报,一个Cursor对象,它是定位在第一项之前,这是我除preT意味着光标在返回的行的开始。如果我添加了 Cursor.moveToFirst()光标访问数据之前,我没有得到任何的异常。到底是怎么回事...

在试图对我的数据库执行查询,我得到这个例外。但是,文档指出该方法 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()。光标懒加载,调用光标被加载到内存这些方法之后。您可以决定什么时候做。

cad里rgb105,105,105颜色对应索引颜色哪一个

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.

阅读全文

相关推荐

最新文章