CursorIndexOutOfBoundsException指数0要求,大小为0 [英] CursorIndexOutOfBoundsException Index 0 requested, with a size of 0

查看:2013
本文介绍了CursorIndexOutOfBoundsException指数0要求,大小为0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的数据库的某一行的文本。对于这一点,我做了这个功能。

I'm trying to get a text from a certain row of my database. For this, I made this function

public String getTranslation(long rowId) throws SQLException {    
    String str = null;
    Cursor mCursor = db.query(
        true, TABLE_LANGUAGE_FR, new String[] {
            KEY_ID_INTERFACE_TEXT, KEY_ITEM_NAME,KEY_FORM_LABEL_ID, KEY_FORM_RANK
        }, 
        KEY_FORM_LABEL_ID + "=" + rowId, null, null, null, null, null
    );

    if (mCursor != null) {
        mCursor.moveToFirst();
        str = mCursor.getString(mCursor.getColumnIndex(KEY_ITEM_NAME));
    }
    return str;
}

和我叫它是这样的:

db = new DbAdapter(this);
db.createDatabase(); 
db.openDataBase();
String str = db.getTranslation(1706);

我的表是这样的:

My table looks like this :

我得到这个错误:

09:32:08.965    307 com.Orange  ERROR   AndroidRuntime  Caused by: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
09:32:08.965    307 com.Orange  ERROR   AndroidRuntime      at android.database.AbstractCursor.checkPosition(AbstractCursor.java:580)
09:32:08.965    307 com.Orange  ERROR   AndroidRuntime      at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:214)
09:32:08.965    307 com.Orange  ERROR   AndroidRuntime      at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:41)
09:32:08.965    307 com.Orange  ERROR   AndroidRuntime      at com.Orange.Database.DbAdapter.getTranslation(DbAdapter.java:141)
09:32:08.965    307 com.Orange  ERROR   AndroidRuntime      at com.Orange.Authentication.onCreate(Authentication.java:32)

为什么会出现这个错误?我在做什么错在这里?

Why am I getting this error? What am I doing wrong here?

先谢谢了。

推荐答案

这似乎就像你有一个emtpy光标。而不是检查它是否为null尝试checkcing

It would seem like you have an emtpy cursor. Instead of checking whether it is null try checkcing

if(mCursor.getCount() > 0)
{
  //do stuff
}

尝试删除您的where条件,以确保在运行SELECT语句时,你实际上得到的数据。
如果你仍然得到什么,你可能有一个错字在你的表名,或无法连接/创建数据库/表。

try removing your where condition to make sure you actually get data when running the select statement. If you still get nothing you might have a typo in your tablenames, or failed to connect/create the database/tables.

Cursor mCursor = db.query("sys_interface_text", new String[] {
       "id_interface_text", "item_name","form_label_id", "form_rank"}, 
               "form_label_id = 1706", null, null, null,
       null);

这篇关于CursorIndexOutOfBoundsException指数0要求,大小为0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆