关于E/AndroidRuntime(32023): Caused by: android.database.CursorIndexOutOfBoundsException: Index 3 requested, with a size of 3的问题

发生错误的代码

/**

* 获取下载列表中的视频名称,

* 若果存在添加的视频与它相同
*
则提示用户该视频已经添加到下载列表
* 备注:添加的视频超过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的问题

时间: 2024-11-05 06:26:06

关于E/AndroidRuntime(32023): Caused by: android.database.CursorIndexOutOfBoundsException: Index 3 requested, with a size of 3的问题的相关文章

Android android.database.CursorIndexOutOfBoundsException:Index -1 requested, with a size of 1

Android中数据库处理使用cursor时,游标不是放在为0的下标,而是放在为-1的下标处开始的. 也就是说返回给cursor查询结果时,不能够马上从cursor中提取值. 下面的代码会返回错误 User u = null; SQLiteDatabase db = dbHelper.getReadableDatabase(); Cursor cursor = db.rawQuery("select * from user where id = ?", new String[] { i

Xamarin.Android 使用 SQLite 出现 Index -1 requested, with a size of 10 异常

异常: Android.Database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 10 此错误是数据返回到ICursor无法确定获取列的索引,那么需要加上一下代码即可. if (i == 0) //确定游标位置 { ic.MoveToFirst(); } else { ic.MoveToNext(); } 完整代码Demo: /// <summary> /// 查询数据 /// </summa

Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f070058 android-studio 3.0 from canary 5 to canary 6

我升级android-studio到了3.0 canary 6打包编译安装出现如下错误: 07-11 13:00:39.523 8913-8913/dcpl.com.myapplication E/AndroidRuntime: FATAL EXCEPTION: main Process: dcpl.com.myapplication, PID: 8913 java.lang.RuntimeException: Unable to start activity ComponentInfo{dcp

解决:Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x2

在运行Android app时出现以下错误: --------- beginning of crash 11-28 07:53:56.485 6712-6712/com.trojane.android.learnactivity E/AndroidRuntime: FATAL EXCEPTION: main Process: com.trojane.android.learnactivity, PID: 6712 java.lang.RuntimeException: Unable to sta

android DataBase的相关操作(建立表结构和创建表)

先建立一个table的基类: public abstract class DbBaseTable { private static final String TAG = "DbBaseTable"; /** * @return the DB table name */ abstract String getName(); /** * Creates the DB table according to the DB scheme * * @param db */ abstract voi

Caused by: android.view.InflateException: Binary XML file line #12: Error inflating class android.support.design.widget.TabLayout,TableLayout引起页面崩溃

在使用TableLayout的时候,运行引用程序直接Crash. FATAL EXCEPTION: main Process: com.edaixi.activity, PID: 9703 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.edaixi.activity/com.edaixi.activity.PriceCenterActivity}: android.view.InflateExcept

android database 相关

以前用database从来都是直接执行,db.execute(). 今天看公司1.0的源码中又学习了一个逻辑, SecureSQLiteDatabase db = null; try { db = mOpenHelper.openDatabase(); db.beginTransaction(); try { todo 数据操作 }; //db 所要执行的操作 db.update(MstDataEntry.TABLE_NAME, values, whereClause, whereArgs);

Caused by: android.os.NetworkOnMainThreadException错误解决办法

错误Caused by: android.os.NetworkOnMainThreadException :查了下原因上在4.0之后在主线程里面执行Http请求都会报这个错,大概是怕Http请求时间太长造成程序假死的情况吧. 解决办法有两个思路,分别是: 第一种方法:直接忽视,强制使用(强烈不推荐,但是修改简单)在MainActivity文件的setContentView(R.layout.activity_main)下面加上如下代码 if (android.os.Build.VERSION.S

android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error(Sqlite code 14): Could not open database,(OS error - 13:Permission denied)

07-24 15:03:14.490 6291-6291/com.tongyan.nanjing.subway E/SQLiteDatabase: Failed to open database '/storage/emulated/0/TYSubway/structure/db/TYSubwayInspcetionNJ.db'. android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error(Sqlite code