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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:55:21+00:00 2026-06-05T15:55:21+00:00

So, I have an application I’m making that can be simply described as a

  • 0

So, I have an application I’m making that can be simply described as a task list. I’m using an SQLite database to store all the data. I’m having various problems with the database, but let’s stick with this more pressing bit here. On a test run, I did a basic input test, and got this logcat entry:

06-13 01:49:33.868: E/Database(482): Error inserting ISCHECKED=0 NOTE=This is a test. _id=0 TASK=Hello World
06-13 01:49:33.868: E/Database(482): android.database.sqlite.SQLiteConstraintException: error code 19: constraint failed
06-13 01:49:33.868: E/Database(482):    at android.database.sqlite.SQLiteStatement.native_execute(Native Method)
06-13 01:49:33.868: E/Database(482):    at android.database.sqlite.SQLiteStatement.execute(SQLiteStatement.java:61)
06-13 01:49:33.868: E/Database(482):    at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1582)
06-13 01:49:33.868: E/Database(482):    at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1426)
06-13 01:49:33.868: E/Database(482):    at com.mowdownDevelopments.nagTasks.NagTasksDatabaseHelper.addTask(NagTasksDatabaseHelper.java:68)
06-13 01:49:33.868: E/Database(482):    at com.mowdownDevelopments.nagTasks.NagTasksAddTaskFragment.save(NagTasksAddTaskFragment.java:65)
06-13 01:49:33.868: E/Database(482):    at com.mowdownDevelopments.nagTasks.NagTasksAddTaskFragment.onOptionsItemSelected(NagTasksAddTaskFragment.java:54)
06-13 01:49:33.868: E/Database(482):    at com.actionbarsherlock.app.SherlockFragment.onOptionsItemSelected(SherlockFragment.java:67)
06-13 01:49:33.868: E/Database(482):    at android.support.v4.app.FragmentManagerImpl.dispatchOptionsItemSelected(FragmentManager.java:1919)
06-13 01:49:33.868: E/Database(482):    at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:357)
06-13 01:49:33.868: E/Database(482):    at com.actionbarsherlock.app.SherlockFragmentActivity.onMenuItemSelected(SherlockFragmentActivity.java:288)
06-13 01:49:33.868: E/Database(482):    at com.actionbarsherlock.ActionBarSherlock.callbackOptionsItemSelected(ActionBarSherlock.java:586)
06-13 01:49:33.868: E/Database(482):    at com.actionbarsherlock.internal.ActionBarSherlockCompat.onMenuItemSelected(ActionBarSherlockCompat.java:526)
06-13 01:49:33.868: E/Database(482):    at com.actionbarsherlock.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:738)
06-13 01:49:33.868: E/Database(482):    at com.actionbarsherlock.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:148)
06-13 01:49:33.868: E/Database(482):    at com.actionbarsherlock.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:879)
06-13 01:49:33.868: E/Database(482):    at com.actionbarsherlock.internal.view.menu.ActionMenuView.invokeItem(ActionMenuView.java:510)
06-13 01:49:33.868: E/Database(482):    at com.actionbarsherlock.internal.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:145)
06-13 01:49:33.868: E/Database(482):    at android.view.View.performClick(View.java:2485)
06-13 01:49:33.868: E/Database(482):    at android.view.View$PerformClick.run(View.java:9080)
06-13 01:49:33.868: E/Database(482):    at android.os.Handler.handleCallback(Handler.java:587)
06-13 01:49:33.868: E/Database(482):    at android.os.Handler.dispatchMessage(Handler.java:92)
06-13 01:49:33.868: E/Database(482):    at android.os.Looper.loop(Looper.java:123)
06-13 01:49:33.868: E/Database(482):    at android.app.ActivityThread.main(ActivityThread.java:3683)
06-13 01:49:33.868: E/Database(482):    at java.lang.reflect.Method.invokeNative(Native Method)
06-13 01:49:33.868: E/Database(482):    at java.lang.reflect.Method.invoke(Method.java:507)
06-13 01:49:33.868: E/Database(482):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-13 01:49:33.868: E/Database(482):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-13 01:49:33.868: E/Database(482):    at dalvik.system.NativeStart.main(Native Method)

I can’t see what the problem is. My method for adding the task to the database is about as simple as it gets:

public void addTask(String title, String notes)
{
    SQLiteDatabase db = getWritableDatabase();
    int newestID = getNewTaskId(db);
    ContentValues values = new ContentValues();
    values.put("_id", newestID);
    values.put("TASK", title);
    values.put("NOTE", notes);
    values.put("ISCHECKED", 0);
    db.insert("TASKS", null, values);
    db.close();
}
@Override
public void onCreate(SQLiteDatabase db) {
    db.execSQL("CREATE TABLE IF NOT EXISTS TASKS (_id INTEGER PRIMARY KEY, TASK TEXT, NOTE TEXT, ISCHECKED INTEGER);");
}
public int getNewTaskId(SQLiteDatabase db)
{
    Cursor c = db.rawQuery("SELECT MAX(_id) FROM TASKS", null);
    int columnID = c.getColumnIndex(ID);
    if (columnID == -1)
    {
        return 0;
    } else {
        return c.getInt(columnID) +1;
    }
}

Can anyone help me out? I don’t see where I’m getting a “Constraint failed”.

  • 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-05T15:55:23+00:00Added an answer on June 5, 2026 at 3:55 pm

    You are getting the MAX id, which means the id already exists. I think you forgot to increment the MAX id before you return it. This is assuming your getNewAlarmId is almost exactly the same as getNewTaskId

    public int getNewAlarmId(SQLiteDatabase db)
    {
        Cursor c = db.rawQuery("SELECT MAX(_id) FROM ALARMS", null);
        int columnID = c.getColumnIndex(ID);
        if (columnID == -1)
        {
            return 0;
        } else {
            return c.getInt(columnID) + 1;
        }
    }
    

    UPDATE

    Try hardcoding the value to like 10. Does it run at least once, then break? If so I think it may be your cursor. You didn’t call moveToFirst like Squonk suggested

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

Sidebar

Related Questions

I have application that is up more than 3 days. I can see in
I have application written in Java that is using EJB3 + Toplink. I'm using
I have application which can export slides to PowerPoint. I'm using Microsoft.Office.Interop.PowerPoint.dll . This
I have application code that inserts a record in a local database and a
I have application that use mysql database, but now i need to port it
I have application that works using Perl's CGI::Fast . Basically mainloop of the code
I have application that makes different queries with different results so the caching in
I have application that is connecting to the DB and if I enter incorrect
I have Application X (not mine!) with Subform x1, x2, x3. How can I
I have application 1 and application 2. App2 needs to verify that App1 is

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.