0
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??

Jiho Ryu
  • 1
  • 1

1 Answers1

-1

I see there 5 data values.You can insert Like this

    ContentValues values = new ContentValues();
    values.put("title", intent.getStringExtra("TITLE"));
    values.put("author", intent.getStringExtra("AUTHOR"));
    values.put("rating", intent.getFloatExtra("RATING", (float) 0.0));
    values.put("quotes", intent.getStringExtra("QUOTES"));
    // Inserting Row
    db.insert("book", null, values);

It should work.

riaz hasan
  • 1,155
  • 2
  • 8
  • 20