android.database.sqlite.SQLiteConstraintException

If you like a tip written by other Samebug users, mark is as helpful! Marks help our algorithm provide you better solutions and also help other users.
tip

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.

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

  • Android Xml data parsing
    via Stack Overflow by hashim
    ,
  • Android database method was called twice
    via Stack Overflow by user4901016
    ,
  • Errors when running
    via Stack Overflow by Alexia White
    ,
  • sending attachment failed
    via GitHub by Safari77
    ,
  • backup database causes crash
    via GitHub by rahu
    ,
  • Android 1.5 crash issue
    via GitHub by mucek4
    ,
    • android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: contacts.name (code 2067) at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method) at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:788) at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:788) at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:86) at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1471) at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1341) at com.example.yasser.ahlysc.MyDataBase.AddnewContact(MyDataBase.java:55) at com.example.yasser.ahlysc.Funny$1.onResponse(Funny.java:59) at com.example.yasser.ahlysc.Funny$1.onResponse(Funny.java:48) at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:60) at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:30) at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:211) at android.app.ActivityThread.main(ActivityThread.java:5389) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815)

    Users with the same issue

    EduvmEduvm
    60 times, last one,
    filipebatistafilipebatista
    1 times, last one,
    Unknown UserUnknown User
    1 times, last one,
    Hiren AmaliyarHiren Amaliyar
    1 times, last one,
    Indri YunitaIndri Yunita
    20 times, last one,
    68 more bugmates