发生错误的代码:
/**
* 获取下载列表中的视频名称,
* 若果存在添加的视频与它相同
*
则提示用户该视频已经添加到下载列表
* 备注:添加的视频超过3时,程序会崩溃
*
抛出错误: android.database.CursorIndexOutOfBoundsException: Index 3
requested, with a size of 3
* @return
*//*
public String
getDownloadingVideoname(){
SQLiteDatabase db =
openHelper.getReadableDatabase();
Cursor cursor = db.query("Downloading",
null, null, null, null, null, null);
String DownloadingVideoname
="";
if(cursor.moveToFirst()){//判断游标是否为空
//遍历游标
for (int i = 0; i
< cursor.getCount(); i++)
{
cursor.move(i);//移动到指定记录
DownloadingVideoname =
cursor.getString(cursor.getColumnIndex("downloadingfilename"));
}
return
DownloadingVideoname;
}
cursor.close();
db.close();
return
null;
}*/
改正后的代码:
/**
* 获取下载列表中的视频名称,
* 若果存在添加的视频与它相同
* 则提示用户该视频已经添加到下载列表
*
@return
*/
public String getDownloadingVideoname(){
SQLiteDatabase
db = openHelper.getReadableDatabase();
Cursor cursor =
db.query("Downloading", null, null, null, null, null, null);
String
DownloadingVideoname ="";
cursor.moveToFirst();//判断游标是否为空
while(!cursor.isAfterLast()){
DownloadingVideoname
=
cursor.getString(cursor.getColumnIndex("downloadingfilename"));
cursor.moveToNext();
}
cursor.close();
db.close();
return
DownloadingVideoname;
}
关于E/AndroidRuntime(32023): Caused by:
android.database.CursorIndexOutOfBoundsException: Index 3 requested, with a size
of 3的问题