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 8089029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:16:31+00:00 2026-06-05T19:16:31+00:00

I am trying to add a new column into an SQLiteDatabase but every time

  • 0

I am trying to add a new column into an SQLiteDatabase but every time I try to run the code with the new column it crashes. If I simply add the new column then it runs alright but when I try to use it in code it crashes. The value in question is KEY_END_TIME and any value with the word “end” in it. I tried passing it the same exact values as KEY_DATE_TIME, more or less using them in the exact same context in an attempt to get it running but it immediately crashes every time. Any help or advice would be greatly appreciated.

/**
 * Simple reminder database access helper class. 
 * Defines the basic CRUD operations (Create, Read, Update, Delete)
 * for the example, and gives the ability to list all reminders as well as
 * retrieve or modify a specific reminder.
 * 
 */
public class RemindersDbAdapter {

//
// Databsae Related Constants
//
private static final String DATABASE_NAME = "data";
private static final String DATABASE_TABLE = "reminders";
private static final int DATABASE_VERSION = 4;

public static final String KEY_TITLE = "title";
public static final String KEY_CUSTOMER = "body";
public static final String KEY_DATE_TIME = "reminder_date_time"; 
public static final String KEY_END_TIME = "reminder_end_time"; 
public static final String KEY_ROWID = "_id";


private static final String TAG = "ReminderDbAdapter";
private DatabaseHelper mDbHelper;
private SQLiteDatabase mDb;

/**
 * Database creation SQL statement
 */
private static final String DATABASE_CREATE =
        "create table " + DATABASE_TABLE + " ("
                + KEY_ROWID + " integer primary key autoincrement, "
                + KEY_TITLE + " text not null, " 
                + KEY_CUSTOMER + " text not null, " 
                + KEY_DATE_TIME + " text not null);"
                + KEY_END_TIME + " text not null);"; 



private final Context mCtx;

private static class DatabaseHelper extends SQLiteOpenHelper {

    DatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {

        db.execSQL(DATABASE_CREATE);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
                + newVersion + ", which will destroy all old data");

        db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);
        onCreate(db);
    }
}

/**
 * Constructor - takes the context to allow the database to be
 * opened/created
 * 
 * @param ctx the Context within which to work
 */
public RemindersDbAdapter(Context ctx) {
    this.mCtx = ctx;
}

/**
 * Open the database. If it cannot be opened, try to create a new
 * instance of the database. If it cannot be created, throw an exception to
 * signal the failure
 * 
 * @return this (self reference, allowing this to be chained in an
 *         initialization call)
 * @throws SQLException if the database could be neither opened or created
 */
public RemindersDbAdapter open() throws SQLException {
    mDbHelper = new DatabaseHelper(mCtx);
    mDb = mDbHelper.getWritableDatabase();
    return this;
}

public void close() {
    mDbHelper.close();
}


/**
 * Create a new reminder using the title, body and reminder date time provided. 
 * If the reminder is  successfully created return the new rowId
 * for that reminder, otherwise return a -1 to indicate failure.
 * 
 * @param title the title of the reminder
 * @param body the body of the reminder
 * @param reminderDateTime the date and time the reminder should remind the user
 * @return rowId or -1 if failed
 */
public long createReminder(String title, String body, String reminderDateTime, String        reminderEndTime) {
    ContentValues initialValues = new ContentValues();
    initialValues.put(KEY_TITLE, title);
    initialValues.put(KEY_CUSTOMER, body);
    initialValues.put(KEY_DATE_TIME, reminderDateTime);
    initialValues.put(KEY_END_TIME, reminderDateTime); 

    return mDb.insert(DATABASE_TABLE, null, initialValues);
}

/**
 * Delete the reminder with the given rowId
 * 
 * @param rowId id of reminder to delete
 * @return true if deleted, false otherwise
 */
public boolean deleteReminder(long rowId) {

    return mDb.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowId, null) > 0;
}

/**
 * Return a Cursor over the list of all reminders in the database
 * 
 * @return Cursor over all reminders
 */
public Cursor fetchAllReminders() {

    return mDb.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_TITLE,
            KEY_CUSTOMER, KEY_DATE_TIME, KEY_END_TIME}, null, null, null, null, null);
}

/**
 * Return a Cursor positioned at the reminder that matches the given rowId
 * 
 * @param rowId id of reminder to retrieve
 * @return Cursor positioned to matching reminder, if found
 * @throws SQLException if reminder could not be found/retrieved
 */
public Cursor fetchReminder(long rowId) throws SQLException {

    Cursor mCursor =

            mDb.query(true, DATABASE_TABLE, new String[] {KEY_ROWID,
                    KEY_TITLE, KEY_CUSTOMER, KEY_DATE_TIME, KEY_END_TIME}, KEY_ROWID +     "=" + rowId, null,
                    null, null, null, null);
    if (mCursor != null) {
        mCursor.moveToFirst();
    }
    return mCursor;

}

/**
 * Update the reminder using the details provided. The reminder to be updated is
 * specified using the rowId, and it is altered to use the title, body and reminder     date time
 * values passed in
 * 
 * @param rowId id of reminder to update
 * @param title value to set reminder title to
 * @param body value to set reminder body to
 * @param reminderDateTime value to set the reminder time. 
 * @return true if the reminder was successfully updated, false otherwise
 */
public boolean updateReminder(long rowId, String title, String body, String reminderDateTime, String reminderEndTime) {
    ContentValues args = new ContentValues();
    args.put(KEY_TITLE, title);
    args.put(KEY_CUSTOMER, body);
    args.put(KEY_DATE_TIME, reminderDateTime);
    args.put(KEY_END_TIME, reminderEndTime);

    return mDb.update(DATABASE_TABLE, args, KEY_ROWID + "=" + rowId, null) > 0;
}

}

06-15 18:11:12.356: E/AndroidRuntime(790): FATAL EXCEPTION: main
06-15 18:11:12.356: E/AndroidRuntime(790): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dummies.android.TaskReminder/com.dummies.android.TaskReminder.TaskReminderActivity}: android.database.sqlite.SQLiteException: no such column: reminder_end_time: , while compiling: SELECT _id, title, body, reminder_date_time, reminder_end_time FROM reminders
06-15 18:11:12.356: E/AndroidRuntime(790):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
06-15 18:11:12.356: E/AndroidRuntime(790):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
06-15 18:11:12.356: E/AndroidRuntime(790):  at android.app.ActivityThread.access$600(ActivityThread.java:123)
06-15 18:11:12.356: E/AndroidRuntime(790):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
06-15 18:11:12.356: E/AndroidRuntime(790):  at android.os.Handler.dispatchMessage(Handler.java:99)
06-15 18:11:12.356: E/AndroidRuntime(790):  at android.os.Looper.loop(Looper.java:137)
06-15 18:11:12.356: E/AndroidRuntime(790):  at android.app.ActivityThread.main(ActivityThread.java:4424)
06-15 18:11:12.356: E/AndroidRuntime(790):  at java.lang.reflect.Method.invokeNative(Native Method)
06-15 18:11:12.356: E/AndroidRuntime(790):  at java.lang.reflect.Method.invoke(Method.java:511)
06-15 18:11:12.356: E/AndroidRuntime(790):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-15 18:11:12.356: E/AndroidRuntime(790):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-15 18:11:12.356: E/AndroidRuntime(790):  at dalvik.system.NativeStart.main(Native Method)
06-15 18:11:12.356: E/AndroidRuntime(790): Caused by: android.database.sqlite.SQLiteException: no such column: reminder_end_time: , while compiling: SELECT _id, title, body, reminder_date_time, reminder_end_time FROM reminders
06-15 18:11:12.356: E/AndroidRuntime(790):  at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
06-15 18:11:12.356: E/AndroidRuntime(790):  at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:68)
06-15 18:11:12.356: E/AndroidRuntime(790):  at android.database.sqlite.SQLiteProgram.compileSql(SQLiteProgram.java:143)
06-15 18:11:12.356: E/AndroidRuntime(790):  at android.database.sqlite.SQLiteProgram.compileAndbindAllArgs(SQLiteProgram.java:361)
06-15 18:11:12.356: E/AndroidRuntime(790):  at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:127)
06-15 18:11:12.356: E/AndroidRuntime(790):  at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:94)
06-15 18:11:12.356: E/AndroidRuntime(790):  at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:53)
06-15 18:11:12.356: E/AndroidRuntime(790):  at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:47)
06-15 18:11:12.356: E/AndroidRuntime(790):  at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1564)
06-15 18:11:12.356: E/AndroidRuntime(790):  at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1449)
06-15 18:11:12.356: E/AndroidRuntime(790):  at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1405)
06-15 18:11:12.356: E/AndroidRuntime(790):  at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1485)
06-15 18:11:12.356: E/AndroidRuntime(790):  at com.dummies.android.TaskReminder.RemindersDbAdapter.fetchAllReminders(RemindersDbAdapter.java:144)
06-15 18:11:12.356: E/AndroidRuntime(790):  at com.dummies.android.TaskReminder.TaskReminderActivity.fillData(TaskReminderActivity.java:40)
06-15 18:11:12.356: E/AndroidRuntime(790):  at com.dummies.android.TaskReminder.TaskReminderActivity.onCreate(TaskReminderActivity.java:33)
06-15 18:11:12.356: E/AndroidRuntime(790):  at android.app.Activity.performCreate(Activity.java:4465)
06-15 18:11:12.356: E/AndroidRuntime(790):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
06-15 18:11:12.356: E/AndroidRuntime(790):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
  • 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-05T19:16:33+00:00Added an answer on June 5, 2026 at 7:16 pm

    Your sql creation string is wrong. Modify it like this:

    ...+ KEY_DATE_TIME + " text not null, "
                    + KEY_END_TIME + " text not null);";
    

    Remember to uninstall and then reinstall your app so the onCreate method is called again and the database recreated.

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

Sidebar

Related Questions

I'm trying to alter a table to add a new column, then insert a
Im trying to add data into a new column I have created in my
I have below updateFile code, here I am trying to add new node when
Im trying to add an element to a database and then return a new
I'm trying to insert into XML column (SQL SERVER 2008 R2), but the server's
Hello I'm trying to add new column to the Excel worksheet by command ALTER
I am trying to add the search toolbar to my jqGrid but running into
I am trying to insert a button column into a datatable but it says
I am new in eclipselink and trying to add extra columns in manyTomany association
I'm trying to add new entries to an sql database using php, i can

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.