SQLiteConstraintException: Fehlercode 19: constraint failed

Anfänger hier wieder wollen Beratung. Versuchen, zu Folgen, ein tutorial für das hinzufügen/Bearbeiten/löschen von Daten zu/von der Datenbank.

Aber ich bekomme die folgende Fehlermeldung, wenn Sie versuchen, um einen neuen Titel:

ERROR/Database(278): Error inserting Book_Title=testtitle Book_Author=testauthor

ERROR/Database(278): android.database.sqlite.SQLiteConstraintException: error code 19: constraint failed

Ich vermute, die einen contraint auf der ID, da die Datenbank bereits erstellt in einer früheren Klasse-Datei. Allerdings bin ich nicht versiert genug mit Java zu wissen, wie es zu lösen ist. Bearbeiten und Löschen von Daten funktionieren.

Code:

DatabaseManager.class:

public void addRow(String rowStringOne, String rowStringTwo)
    {
        //this is a key value pair holder used by android's SQLite functions
        ContentValues values = new ContentValues();


        values.put(TABLE_ROW_ONE, rowStringOne);
        values.put(TABLE_ROW_TWO, rowStringTwo);


        //ask the database object to insert the new data 
        try{db.insert(TABLE_NAME, null, values);}
        catch(Exception e)
        {
            Log.e("DB ERROR", e.toString());
            e.printStackTrace();
        }
    }



private class CustomSQLiteOpenHelper extends SQLiteOpenHelper
    {



        public CustomSQLiteOpenHelper(Context context)
        {
            super(context, DB_NAME, null, DB_VERSION);
        }

        @Override
        public void onCreate(SQLiteDatabase db)
        {
            //This string is used to create the database.  It should
            //be changed to suit your needs.
            String newTableQueryString = "create table " +
                                        TABLE_NAME +
                                        " (" +
                                        TABLE_ROW_ID + " integer primary key autoincrement not null," +
                                        TABLE_ROW_ONE + " text," +
                                        TABLE_ROW_TWO + " text" +
                                        ");";




            //execute the query string to the database.
            db.execSQL(newTableQueryString);

        }


        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
        {
            //NOTHING TO DO HERE. THIS IS THE ORIGINAL DATABASE VERSION.
            //OTHERWISE, YOU WOULD SPECIFIY HOW TO UPGRADE THE DATABASE.
        }
    } 
}

AddData.class:

private void addRow()
{
    try
    {
        //ask the database manager to add a row given the two strings
        db.addRow
        (

                textFieldOne.getText().toString(),
                textFieldTwo.getText().toString()

        );

        //request the table be updated
        updateTable();

        //remove all user input from the Activity
        emptyFormFields();
    }
    catch (Exception e)
    {
        Log.e("Add Error", e.toString());
        e.printStackTrace();
    }
}
InformationsquelleAutor d347hkn3ll | 2011-05-20
Schreibe einen Kommentar