ContentValues放错误

时间:2016-04-12 19:44:29

标签: android sqlite insert content-values

继续收到此错误:

Error inserting android.database.sqlite.SQLiteException: near "null": syntax error (code 1): 
, while compiling: INSERT INTO exercises(null) VALUES (NULL)

我正在尝试在创建SQLite数据库时将值插入其中。我知道我应该使用预先填充的数据库,但我只需插入几个值。第一个ContentValues投放了,但其他两个没有。

该错误似乎在抱怨

database.insert("exercises", null, row2);

在此文件中:

MySQLiteHelper

@Override
public void onCreate(SQLiteDatabase database) {
    Log.d(MainActivity.DEBUG_TAG, "Creating db: " + DATABASE_CREATE);

    database.execSQL(DATABASE_CREATE);

    ContentValues row = new ContentValues();
    row.put(COLUMN_ID, "1");
    row.put(COLUMN_NAME, "Bench press");
    row.put(COLUMN_MUSCLE, "Chest");
    row.put(COLUMN_DESC, "Compound exercise, go heavy for 5-8 reps.");
    row.put(COLUMN_IMAGE, "http://i.imgur.com/2ATluZ4.jpg");
    database.insert("exercises", null, row);

    ContentValues row2 = new ContentValues();
    row2.put(COLUMN_ID, "2");
    row2.put(COLUMN_NAME, "Incline bench press");
    row2.put(COLUMN_MUSCLE, "Chest");
    row2.put(COLUMN_DESC, "Compound exercise, use moderate weight for 8-12 reps.");
    row2.put(COLUMN_IMAGE, "http://i.imgur.com/QgyzpZH.jpg");
    database.insert("exercises", null, row2);

    ContentValues row3 = new ContentValues();
    row3.put(COLUMN_ID, "3");
    row3.put(COLUMN_NAME, "Chest flyes");
    row3.put(COLUMN_MUSCLE, "Chest");
    row3.put(COLUMN_DESC, "Isolation exercise. Go light for 12-15 reps.");
    row3.put(COLUMN_IMAGE, "http://i.imgur.com/6Xtu7Il.png");
    database.insert("exercises", null, row3);

}

1 个答案:

答案 0 :(得分:0)

试试!!!

database.insert(" exercises ", null, row2);