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

  • SEARCH
  • Home
  • 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 8331753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:30:44+00:00 2026-06-09T02:30:44+00:00

I have created an SQLiteOpenHelper subclass to store reminders. I create a table in

  • 0

I have created an SQLiteOpenHelper subclass to store reminders.
I create a table in this class as follows:

public static final String TABLE = "Reminders";
public static final String ID = "id";
public static final String COMPLETE = "complete";
public static final String PRIORITY = "priority";
public static final String DATE = " alarmdate";
public static final String TITLE = "title";
public static final String NOTES = "notes";

@Override
public void onCreate(SQLiteDatabase db) {
    String create = "CREATE TABLE " + TABLE + "(\n" 
            + ID + " INTEGER PRIMARY KEY, \n" 
            + COMPLETE + " INTEGER DEFAULT 0, \n" 
            + PRIORITY + " INTEGER DEFAULT 1, \n"
            + DATE + " CHAR(21) DEFAULT NULL, \n"
            + TITLE + " TEXT NOT NULL, \n" 
            + NOTES + " TEXT DEFAULT NULL \n"
            + ");";
    db.execSQL(create);
}

The database is created fine and I am able to add entries normally.

The problem is that, when I want to retrieve a row from the database, cursor.getColumnIndex(DATE) returns -1, while it returns the correct indexes for the other fields:

//Method of the helper class
public Reminder getReminder(int _id) {
    Reminder r;

    SQLiteDatabase db = getReadableDatabase();
    String query = String
            .format("SELECT * FROM %s WHERE ID=%d", TABLE, _id);
    Cursor cursor = db.rawQuery(query, null);

    cursor.moveToFirst();

    if (cursor.isAfterLast())
        return null;

    boolean complete = (cursor.getInt(cursor.getColumnIndex(COMPLETE)) != 0);
    int priority = cursor.getInt(cursor.getColumnIndex(PRIORITY));
    String dateS = cursor.getString(cursor.getColumnIndex(DATE)); //cursor.getColumnIndex(DATE) returns -1;

    //etc...
    cursor.close();

It’s quite annoying, as getColumnIndex() returns a valid index for all the other fields.

Even more, calling cursor.getString(3) instead of cursor.getString(cursor.getColumnIndex(DATE)), I get the date value correctly.

What might be the cause of this and how could I fix it?

  • 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-09T02:30:45+00:00Added an answer on June 9, 2026 at 2:30 am

    Try removing the leading space from " alarmdate".

    If that doesn’t do it, try changing CHAR(21) to TEXT, which means exactly the same as far as SQLite is concerned.

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

Sidebar

Related Questions

I have a db that is created like this... public class DataBaseManager extends SQLiteOpenHelper{
I have created a database by extending SQLiteOpenHelper class. And its created also. This
I have created a sub class (DatabaseHelper) of SQLiteOpenHelper Class.Its has a constructor and
I have created a class call DatabaseHandler extending SQLiteOpenHelper. I want to explicting deleted
I have a database helper class private static class DatabaseHelper extends SQLiteOpenHelper{ DatabaseHelper(Context context){
I have a database that I have created with the following handler: public class
I have created SQLiteOpenHelper class to help me open write the database. but i
i have created class cl_DBHandler which extends SQLiteOpenHelper . and i have created class
public class DatabaseHandler extends SQLiteOpenHelper { // All Static variables // Database Version private
I have created two imageViews promatically as shown below: public void createImageViews(Integer count){ ImageView[]

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.