About E/androidruntime (32023): caused By:android.database.CursorIndexOutOfBoundsException:Index 3 requested, with a size of 3 issues

Source: Internet
Author: User

code where the error occurred :

/**

* Get the video name from the download list,

* If there is added video same as it
* Prompts the user that the video has been added to the download list
* Note: The program crashes when you add more than 3 o'clock video
* Throw Error: 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 ()) {//determines if the cursor is empty
Traversing cursors
for (int i = 0; i < Cursor.getcount (); i++) {
Cursor.move (i);//move to the specified record
Downloadingvideoname = cursor.getstring (Cursor.getcolumnindex ("Downloadingfilename"));
}
return downloadingvideoname;
}
Cursor.close ();
Db.close ();
return null;
}*/

Corrected code:

/**
* Get the video name from the download list,
* If there is added video same as it
* Prompts the user that the video has been added to the download list
* @return
*/
Public String Getdownloadingvideoname () {
Sqlitedatabase db = Openhelper.getreadabledatabase ();
cursor cursor = db.query ("Downloading", NULL, NULL, NULL, NULL, NULL, NULL);
String downloadingvideoname = "";
Cursor.movetofirst ();//Determine if the cursor is empty
while (!cursor.isafterlast ()) {
Downloadingvideoname = cursor.getstring (Cursor.getcolumnindex ("Downloadingfilename"));
Cursor.movetonext ();
}
Cursor.close ();
Db.close ();
return downloadingvideoname;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.