android.database.sqlite.SQLiteConstraintException

UNIQUE constraint failed: Note._id(Sqlite code 1555),(OS error - 2:No such file or directory)

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.


rafaelrafael

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

Solutions on the web144

  • via GitHub by chenzj-king
    ,
  • via Stack Overflow by Sadragos
    ,
  • Stack trace

    • android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: Note._id(Sqlite code 1555),(OS error - 2:No such file or directory) at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method) at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:782) at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:788) at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:86) at org.greenrobot.greendao.AbstractDao.insertInsideTx(AbstractDao.java:368) at org.greenrobot.greendao.AbstractDao.executeInsert(AbstractDao.java:351) at org.greenrobot.greendao.AbstractDao.insert(AbstractDao.java:319) at com.dreamliner.greendaosample.ui.activity.main.MainActivity.onClick(MainActivity.java:65) at com.dreamliner.greendaosample.ui.activity.main.MainActivity_ViewBinding$1.doClick(MainActivity_ViewBinding.java:39) at butterknife.internal.DebouncingOnClickListener.onClick(DebouncingOnClickListener.java:22) at android.view.View.performClick(View.java:4768) at android.view.View$PerformClick.run(View.java:19692) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5539) 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:960) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

    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

    deallocdealloc
    4 times, last one
    jkjk
    2 times, last one
    Hiren AmaliyarHiren Amaliyar
    Once,
    bayukresnobayukresno
    617 times, last one
    xaviloxavilo
    Once,
    68 more bugmates