Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1024751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:49:30+00:00 2026-05-16T11:49:30+00:00

I am creating an application where I am calling my database from a different

  • 0

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, it’s now

“android.database.sqlite.SQLiteConstraintException: error code 19:
constraint failed”

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:

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;
        }
}

and here is the main error output:

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

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

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

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

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

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

08-23 22:38:17.104: ERROR/Database(775):at com.Memo.NewItem.save(NewItem.java:365)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T11:49:30+00:00Added an answer on May 16, 2026 at 11:49 am

    In your onUpgrade event, you are dropping the table DATABASE_NAME, but shouldn’t that be DATABASE_TABLE?

    Nothing (besides that) jumps out at me, are you getting this error when you instantiate your DBAdapter object? Is the error happening in the onCreate event or someplace else?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating an Excel file dynamically(data coming from database). on calling the URL
I'm using WPF for creating my application, I am calling a windows form using
I am creating desktop application in winform that will use Sqlite Database. So I
I have been working on creating an application that sends a string from an
I have an C# application (foo) from which I am calling another C# application
I have a local, SQL Server Compact database in an application I am creating.
Im creating application in java using XML. XML- <?xml version=1.0 encoding=UTF-8?> <songlist id=slist> <song
I am creating application where in i have used preferences for changing font settings.
I'm write installer for my web site. Installer creating application pool, virtual directory and
i creating an application with movie animation , i have a animation some group

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.