samedi 12 décembre 2015

android SQLite table book has 4 columns but 5 values were supplied

title = intent.getStringExtra("TITLE");
    author = intent.getStringExtra("AUTHOR");
    rating = intent.getFloatExtra("RATING", (float) 0.0);
    quotes = intent.getStringExtra("QUOTES");

    myDBHelper = new MyDBHelper(getApplicationContext());

    SQLiteDatabase db = myDBHelper.getWritableDatabase();

    String sql = String.format("INSERT INTO book VALUES(null,'%s','%s',%f,'%s')",title,author,rating,quotes);

yes i inserted 4 vales but error message shows "5 values were supplied"

this is my DB class

    @Override
    public void onCreate(SQLiteDatabase db) {

        String sql = "CREATE TABLE book ( _id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT , author TEXT , rating REAL , quotes TEXT);";
        db.execSQL(sql);


    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

        String sql = "DROP TABLE book IF EXISTS book;";
        db.execSQL(sql);

        onCreate(db);

    }

and i get this message on the logcat

12-12 22:22:57.740 9757-9757/? E/AndroidRuntime: ... table book has 4 columns but 5 values were supplied: , while compiling: INSERT INTO book VALUES(null,'null','null',0.000000,'null')

Why??

Aucun commentaire:

Enregistrer un commentaire