English 中文(简体)
如何解决库斯尔·内德韦福·博恩德
原标题:How to resolve CursorIndexOutOfBounds

迄今为止,这已使我陷入困境。

我在试图处理这一具体问题时,不断找一个库尔斯·内德韦特·博恩。

    Cursor c = db.rawQuery("SELECT * FROM table WHERE _id= 2 " , null);

但奇怪的是,我要问的是,我正在坐下来,从那张桌上得出所有——补贴价值。 产出1至100,因此我知道这一数值是存在的。 我也产出所有各栏,它们都是我所期望的。

尽管我很相信存在一些价值观,在正确的一栏中,这一法典的行文仍然 t着库斯尔·内德韦特博恩。 任何人都可以提出解决这一问题的途径。

    numval = c.getInt(c.getColumnIndex("_id"));

伐木

11-21 11:35:09.367: ERROR/AndroidRuntime(11664): Caused by: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0

EDIT

这里是我正在执行的准确守则。 我仍在犯我刚才在句子上留下的错误。

    Cursor cur = db.rawQuery("SELECT * FROM table" , null);
    cur.moveToFirst();
    while (cur.isAfterLast() == false) {

        numval = cur.getInt(cur.getColumnIndex("_id"));
        String numvalval = Integer.toString(numval);
        Log.e("RESULT",numvalval);
        cur.moveToNext();
    }
    cur.close();
    Cursor ti = db.rawQuery("PRAGMA table_info(table)", null);
    if ( ti.moveToFirst() ) {
        do {
            Log.e("COLUMN NAMES","col:  " + ti.getString(1) +" ");
        } while (ti.moveToNext());
    }
    ti.close();
    Cursor c = db.rawQuery("SELECT * FROM table WHERE _id= 2 " , null);
    c.moveToFirst();
                numval      = c.getInt(c.getColumnIndex("_id"));

产出

11-21 13:27:25.906: ERROR/RESULT(13377): 1
11-21 13:27:25.906: ERROR/RESULT(13377): 2
11-21 13:27:25.910: ERROR/COLUMN NAMES(13377): col:  _id 
11-21 13:27:25.910: ERROR/COLUMN NAMES(13377): col:  country 
问题回答

<>See edit,以下建议经编辑后不再有效。

当你收到<代码>Cursor的标语时,在开始时,你应始终将它移至第一行。 因此,你的法典应当如此:

if(c.moveToFirst()) {
    numval = c.getInt(c.getColumnIndex("_id"));
}
else {
    /* SQL Query returned no result ... */
}

EDIT
Change your query to this(without quotes around 2 ):

Cursor c = db.rawQuery("SELECT * FROM table WHERE _id=2" , null);

这意味着,如果您没有这一指数,numval = c.getInt(c.getColumnIndex(“_id”);,首先检查你的 cur,无效或无if(c.getCount>0)

Try using c.move ToFirst(); before numval = c.getInt (c.getColumnIndex ("_id”);

while (cur.isAfterLast() == false) {

这不是正确的做法。

while (cur.moveToNext()) {

is

Also, Cursor has more specific methods tahn rawQuery, you should use these





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...