android.database.sqlite.SQLiteConstraintException

error code 19: constraint failed

Samebug tips1

activity.OnCreate is executed every time the app launches or the screen is rotated, so, putting your DB initialization inside it will cause the DB to be called too many times causing the exception. Try to use the MyDatabase.onCreate method for this.

Don't give up yet. Our experts can help. Paste your full stack trace to get a solution.

Solutions on the web304

  • error code 19: constraint failed
  • via GitHub by mucek4
    , 1 year ago
    error code 19: constraint failed
  • via Stack Overflow by Arshad Ali
    , 1 year ago
    error code 19: constraint failed
  • Stack trace

    • android.database.sqlite.SQLiteConstraintException: error code 19: constraint failed at android.database.sqlite.SQLiteStatement.native_execute(Native Method) at android.database.sqlite.SQLiteStatement.execute(SQLiteStatement.java:66) at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1313) at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1173)

    Write tip

    You have a different solution? A short tip here would help you and many other users who saw this issue last week.

    Users with the same issue

    24 times, 2 weeks ago
    5 times, 2 weeks ago
    Once, 1 month ago
    20 times, 3 months ago
    41 times, 5 months ago
    64 more bugmates