Android Database Problems
<p>i am creating an application where i am calling my database from a different activity but i keep getting all sorts of errors from on the database side of things. At first i was getting an "SQLiteException no such data" and when i deleted my application and installed it back, its now "android.database.sqlite.SQLiteConstraintException: error code 19: constraint failed".</p>

<p>i have no idea what to do anymore. Have gone through so many different examples on creating database but i don't know if i am missing something?.. Here is my code for the database side:</p>

<pre><code>import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;


public class DBAdapter {

    private static final String DATABASE_NAME = "MemoData.db";
    private static final int DATABASE_VERSION = 1;
    public static final String DATABASE_TABLE = "Memo";

    public static final String KEY_ID = "_id";
    public static final String NAME = "Title";
    public static final String START_DATE = "start_date";
    public static final String END_DATE = "end_date";
    public static final String NOTES = "notes";

    private static final String TAG = "DBAdapter";

    private static final String DATABASE_CREATE = "create table Memo (_id integer primary key autoincrement,"   
        + "Title text not null, start_date text not null,"
        + "end_date text not null, "
        + "notes text not null);";

    private final Context context;   
    private DBHelper dbhelper;
    private SQLiteDatabase db;

    public DBAdapter(Context context) {
        this.context = context;
        dbhelper = new DBHelper(context);
    }

    private static class DBHelper extends SQLiteOpenHelper {

        DBHelper(Context context){
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
        }

        @Override
        public void onCreate(SQLiteDatabase db) {
            db.execSQL(DATABASE_CREATE);
        }


        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            Log.w(TAG,"upgrading Database from version"+ oldVersion+ "to"
                    +newVersion+ "which oold data will be lost");
            db.execSQL("DROP TABLE IF EXITS Memo");
            onCreate(db);
        }
    }

    public DBAdapter open()throws SQLException {
        db = dbhelper.getWritableDatabase();
        return this;
    }

    public void close(){
        dbhelper.close();
    }

  public long createItem(String Title, String start_date,String end_date,String notes){
             open();
            ContentValues initialValues = new ContentValues();
            initialValues.put(NAME, Title);
            initialValues.put(START_DATE, start_date);
            initialValues.put(END_DATE, end_date);
            initialValues.put(NOTES, notes);

            return db.insert(DATABASE_TABLE, null, initialValues);
            }

      public Cursor retrieveItems(){
            SQLiteDatabase db = dbhelper.getWritableDatabase();
            String[] resultColumns = new String[] {NAME,START_DATE,END_DATE,NOTES };     
     Cursor cursor = db.query(DATABASE_TABLE, resultColumns, null, null, null, null, null);

            Integer cindex = cursor.getColumnIndex("Title");
            String result = "Result = ";

            if(cursor.moveToFirst()){
                do {
                    result += cursor.getString(cindex)+ "-";
                }while(cursor.moveToNext());
            }
            return cursor;
        }
}
</code></pre>

<p>and here is the main error output:</p>

<p>08-23 22:38:17.104: ERROR/Database(775): Error inserting notes=Notes: end_date=Due Date: Title=Name of Item: start_date=Start Date:
08-23 22:38:17.104:ERROR/Database(775): android.database.sqlite.SQLiteConstraintException: error code 19: constraint failed</p>

<p>08-23 22:38:17.104: ERROR/Database(775):at android.database.sqlite.SQLiteStatement.native_execute(Native Method)</p>

<p>08-23 22:38:17.104: ERROR/Database(775):at android.database.sqlite.SQLiteStatement.execute(SQLiteStatement.java:66)</p>

<p>08-23 22:38:17.104: ERROR/Database(775):at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1313)</p>

<p>08-23 22:38:17.104: ERROR/Database(775):at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1173)</p>

<p>08-23 22:38:17.104: ERROR/Database(775):at com.Memo.DBAdapter.createItem(DBAdapter.java:94)</p>

<p>08-23 22:38:17.104: ERROR/Database(775):at com.Memo.NewItem.save(NewItem.java:365)</p>
