0

我只是无法获得我的数据库列的索引,而其他列索引工作正常。该列是图像(item4)和我得到-1的索引

CursorDb.moveToFirst();
            if (CursorDb.getCount()>0)
                do
                { 
                    int i=CursorDb.getColumnIndex(item2);//ok
                    int t=CursorDb.getColumnIndex(item3);//ok
                    int z=CursorDb.getColumnIndex(item4);//not ok
                    byte b[]=CursorDb.getBlob(4);

我的创建代码和插入工作正常。创建是

private static final String DATABASE_CREATE =
        "create table if not exists  titles (_id integer primary key autoincrement, "
                + "link text not null UNIQUE, RssTitle text not null,Rtl text not null,image BLOB);";

感谢帮助!

4

1 回答 1

2

如果getColumnIndex()返回 -1,则表示该列不在您的查询中。仔细检查您的 SELECT 语句并添加item4.

"SELECT " + item2 + ", " + item3 + ", " + item4 + ", FROM " + TABLE_NAME....  

Cursor#moveToFirst()返回 true 或 false,具体取决于 Cursor 是否为空。您不需要同时使用moveToFirst()and getCount()

if(CursorDb.moveToFirst())
    do 
    {
于 2012-12-22T17:07:28.307 回答