Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8929503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:41:04+00:00 2026-06-15T08:41:04+00:00

In my Android app, I’m trying to retrieve a string from my database based

  • 0

In my Android app, I’m trying to retrieve a string from my database based on the date. But I don’t want the year in the date (that way I only have to have 365 rows). The only way I’ve gotten it to work is in my DB, have the date in the Date column be in the format yyyyMMdd. If I change all the dates in the Date column to be in the format MMdd, the double digit months (like Oct, Nov, Dec) work, but the single digit months like Jan. or Sept. (01, 09) crash the app with the error CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0. I’ve tried the formats MM-dd, yyyy-MM-dd, in the DB and they crash the app with the error listed above. Is it not possible to have the date formatted with just MMdd in a Sqlite database? Any ideas?

MainActivity:

    DBT = new SimpleDateFormat("MMdd", Locale.US);
tMMddStr = DBT.format(new Date(System.currentTimeMillis()));

private void getTH() {

    dba.open();
    tArray = dba.getTHA(tMMddStr);
    dba.close();
    optionB_TV.setText(todayArray[2]);
    hideDayAtv.setText(todayArray[1]);
    hideYearAtv.setText(todayArray[0]);

}

DBAdapter:

    public String[] getTHA(String tMMddStr) {   
    String[] columns = new String[] { KEY_Y, KEY_MD, KEY_HA };
    Cursor cursor = db.query(DB_TABLE, columns, KEY_DATE + "=" + tMMddStr,
            null, null, null, null);

    if (cursor != null) {
        cursor.moveToFirst();
        String hapT[] = new String[3];
        hapT[0] = cursor.getString(0);
        hapT[1] = cursor.getString(1);
        hapT[2] = cursor.getString(2);
        cursor.close();
        this.db.close();
        return hapT;
    }
    return null;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T08:41:05+00:00Added an answer on June 15, 2026 at 8:41 am
    CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
    

    This error means that you are trying to read an empty Cursor, simply check if the Cursor has any data before trying to read it:

    if (cursor != null && cursor.moveToFirst()) {
    

    As far as the single digit month problem, this could be related to the KEY_DATE column’s data type. If KEY_DATE is any type of number, it will strip out the first 0. Try doing the same to tMMddStr.
    (If this didn’t help, post your tables CREATE statement and a few examples of how you are putting data into the database and pulling it out.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The android app reads from database but doesnt write anything to DB, the app
My Android App has a products table in an SQLite database that comes pre-populated
My android app will work for both normal and hdpi device. I don't want
My Android app is a client that fetchs datas from a Web Service and
My Android app stores its SQLite database on the SD card, so that when
My android-app gets List in the one activity, but activity,that contains the LisView for
In Android app i want to return JSONObject from doInBackground() method to onPostExecute() method.
My Android app looks great at 480x800 pixels resolution but it breaks at LDPI
My android app requires that the device has an SDcard and that SDcard is
android app with phone gap but the images in the html pages are bigger

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.