android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: contacts.name (code 2067)

Searched on Google with the first line of a JAVA stack trace?

We can recommend more relevant solutions and speed up debugging when you paste your entire stack trace with the exception message. Try a sample exception.

Recommended solutions based on your search

Samebug tips

,
Expert 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.

Solutions on the web

via Stack Overflow by Yasser Taha
, 1 year ago
UNIQUE constraint failed: contacts.name (code 2067)
via Stack Overflow by hashim
, 1 year ago
UNIQUE constraint failed: context.context_id (code 2067)
via Stack Overflow by Alexia White
, 1 year ago
UNIQUE constraint failed: context.context_id (code 2067)
via Stack Overflow by Unknown author, 1 year ago
UNIQUE constraint failed: event.id (code 1555)
via Stack Overflow by seon
, 9 months ago
UNIQUE constraint failed: bookmark.Id (code 1555)
via Stack Overflow by Tony
, 11 months ago
PRIMARY KEY must be unique (code 19)
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 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)

Users with the same issue

6 times, 1 year ago
5 times, 1 month ago
2 times, 1 year ago
60 times, 1 year ago
2 times, 2 months ago
72 more bugmates

Know the solutions? Share your knowledge to help other developers to debug faster.