Bobsus88
Bobsus88

Reputation: 11

Error insert SQLite Android

I have created this table

private static class PuntataMetaData {
    static final String TABLE_NAME = "puntata";
    static final String ID = "_id";
    static final String PALINSESTO = "palinsesto";
    static final String NUMEROPALINSESTO = "numeroPalinsesto";
    static final String ESITO = "esito";
    static final String PARTITA = "partita";
    static final String QUOTAZIONE = "quotazione";
}


private static final String PUNTATA_TABLE_CREATE =
        "CREATE TABLE " + PuntataMetaData.TABLE_NAME + " (" +
                PuntataMetaData.ID + " integer primary key autoincrement, " +
                PuntataMetaData.PALINSESTO + " double not null, " +
                PuntataMetaData.NUMEROPALINSESTO + " integer not null, " +
                PuntataMetaData.ESITO + " text not null, " +
                PuntataMetaData.PARTITA + "text not null," +
                PuntataMetaData.QUOTAZIONE + " text not null);";

Now when I search to execute this code

public void inserisciInSchedina(Partite p, String esito, String quot){
    db = getWritableDatabase();
    ContentValues cv = createPuntataContentValues(p.getPalinsesto(), p.getNumeroEvento(), esito, quot, p.getPartita());
    db.insert(PuntataMetaData.TABLE_NAME, null, cv);
    db = getReadableDatabase();
}

private ContentValues createPuntataContentValues(long pal, int numPal, String temp, String temp1, String par) {
    ContentValues cv = new ContentValues();
    cv.put(PuntataMetaData.PALINSESTO, pal);
    cv.put(PuntataMetaData.NUMEROPALINSESTO, numPal);
    cv.put(PuntataMetaData.ESITO, temp);
    cv.put(PuntataMetaData.PARTITA, "Inter-Roma");
    cv.put(PuntataMetaData.QUOTAZIONE, temp1);
    return cv;
}

The Android's debug said to me the following error:

android.database.sqlite.SQLiteException: table puntata has no column named partita: , while compiling: INSERT INTO puntata(numeroPalinsesto,esito,quotazione,partita,palinsesto) VALUES (?,?,?,?,?)

I don't understand where is the error because the field "Partita" exists into the DB Thanks

Upvotes: 0

Views: 1608

Answers (3)

Nagaraja
Nagaraja

Reputation: 581

Once you change the DB i mean Table like you change the creation of the table then you need to un-install the app in emulator and run it again that will create new version of DB then you can add your data

Upvotes: 1

CL.
CL.

Reputation: 180280

PuntataMetaData.PARTITA + "text not null," +

You are creating a column with the name partitatext and the type not null.

Upvotes: 1

Majid Daeinejad
Majid Daeinejad

Reputation: 1037

Go to the Application Manager on your device or your emulator and click on "clear data" button. Then check it again. maybe you create table first without partita column and then you decide to do it. It's better using Database Version in your SQLiteOpenHelper Class to control these problems.

Upvotes: -1

Related Questions