0

不断收到此错误:

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

我试图在创建 SQLite 数据库时将值插入到我的 SQLite 数据库中。我知道我应该使用预填充的数据库,但我只有几个值要插入。第一个 ContentValues put 有效,但其他两个无效。

该错误似乎在抱怨

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);

}
4

1 回答 1

0

试试看!!!

database.insert(" exercises ", null, row2);
于 2016-04-13T03:08:13.657 回答