title: android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed:
body: <p>Error</p>
  
  <pre><code> FATAL EXCEPTION: main
                                                                               Process: com.appmaster.akash.messageplus, PID: 14373
                                                                               android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: UserData.RecieversID (code 1555)
                                                                                   at android.database.sqlite.SQLiteConnection.nativeExecuteForChangedRowCount(Native Method)
                                                                                   at android.database.sqlite.SQLiteConnection.executeForChangedRowCount(SQLiteConnection.java:734)
                                                                                   at android.database.sqlite.SQLiteSession.executeForChangedRowCount(SQLiteSession.java:754)
                                                                                   at android.database.sqlite.SQLiteStatement.executeUpdateDelete(SQLiteStatement.java:64)
                                                                                   at android.database.sqlite.SQLiteDatabase.updateWithOnConflict(SQLiteDatabase.java:1579)
                                                                                   at android.database.sqlite.SQLiteDatabase.update(SQLiteDatabase.java:1525)
                                                                                   at com.appmaster.akash.messageplus.Chat.mMessagesSent(Chat.java:918)
                                                                                   at com.appmaster.akash.messageplus.Chat.sendMessage(Chat.java:709)
                                                                                   at com.appmaster.akash.messageplus.Chat.access$900(Chat.java:76)
                                                                                   at com.appmaster.akash.messageplus.Chat$5.onClick(Chat.java:442)
                                                                                   at android.view.View.performClick(View.java:6256)
                                                                                   at android.view.View$PerformClick.run(View.java:24701)
                                                                                   at android.os.Handler.handleCallback(Handler.java:789)
                                                                                   at android.os.Handler.dispatchMessage(Handler.java:98)
                                                                                   at android.os.Looper.loop(Looper.java:164)
                                                                                   at android.app.ActivityThread.main(ActivityThread.java:6541)
                                                                                   at java.lang.reflect.Method.invoke(Native Method)
                                                                                   at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
  </code></pre>
  
  <p><strong>Inserting</strong></p>
  
  <pre><code> MainData helper = new MainData(this); //Change the name to your Helper Class name
      SQLiteDatabase db = helper.getWritableDatabase();
      ContentValues contentValues = new ContentValues();
      contentValues.put(KEY_ID, MessageRecieverId);
      contentValues.put(KEY_NAME, MessageRecieverName);
      contentValues.put(KEY_MESSAGES_SENT, 0);
      contentValues.put(KEY_MESSAGES_RECIEVED, 0);
      contentValues.put(KEY_TIME_SPENT, "");
  
      long returnVariable = db.insert(TABLE_USER_DATA,null,contentValues);
      if (returnVariable == -1) {
          Toast.makeText(getApplication(), "Nope", Toast.LENGTH_LONG).show();
  </code></pre>
  
  <p>No problem in inserting but while updating im getting this error</p>
  
  <p><strong>Updating</strong></p>
  
  <pre><code> MainData helper = new MainData(this); //Change the name to your Helper Class name
      SQLiteDatabase db = helper.getWritableDatabase();int userData = 0;
      Cursor data2 = helper.getUserData();
      while (data2.moveToNext()) {
          userData = data2.getInt(data2.getColumnIndex("MessagesSent"));
      }
      ContentValues contentValues2 = new ContentValues();
      contentValues2.put(KEY_ID, MessageRecieverId);
      contentValues2.put(KEY_MESSAGES_SENT, userData+1);
      long returnVariable2 = db.update(TABLE_USER_DATA, contentValues2,null,null);
      if (returnVariable2 == -1) {
          Toast.makeText(getApplication(), "Nope", Toast.LENGTH_LONG).show();
          //-1 means there was an error updating the values
      } else {
          Toast.makeText(getApplication(),"uf", Toast.LENGTH_SHORT).show();
      }
  </code></pre>
  
  <p>Anyone know why this is so?  .................................................................................................................................................</p>