我一直在尝试引用旧代码来创建表格。我更改了新表的键/列名称,一切正常。但是,当我试图从"费用"更改名称时(从旧代码)到"交易" (新代码)。我得到了
E/SQLiteLog: (1) near "transaction": syntax error
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.cs465.groceryrun.groceryrun, PID: 7199
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.cs465.groceryrun.groceryrun/com.cs465.groceryrun.groceryrun.Transactions}: android.database.sqlite.SQLiteException: near "transaction": syntax error (code 1): , while compiling: CREATE TABLE transaction (_id INTEGER PRIMARY KEY,title TEXT,person TEXT,role TEXT,date TEXT,due_date TEXT,status TEXT,rating REAL,amount REAL);
我所做的就是改变TABLE_NAME:
public static abstract class TransactionTable implements BaseColumns {
public static final String TABLE_NAME = "expense";
public static final String COLUMN_NAME_TITLE = "title";
public static final String COLUMN_NAME_PERSON = "person";
public static final String COLUMN_NAME_ROLE = "role";
public static final String COLUMN_NAME_DATE = "date";
public static final String COLUMN_NAME_DUE_DATE = "due_date";
public static final String COLUMN_NAME_STATUS = "status";
public static final String COLUMN_NAME_RATING = "rating";
public static final String COLUMN_NAME_AMOUNT = "amount";
public static final String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + " (" +
_ID + " INTEGER PRIMARY KEY," +
COLUMN_NAME_TITLE + TEXT_TYPE + COMMA_SEP +
COLUMN_NAME_PERSON + TEXT_TYPE + COMMA_SEP +
COLUMN_NAME_ROLE + TEXT_TYPE + COMMA_SEP +
COLUMN_NAME_DATE + TEXT_TYPE + COMMA_SEP +
COLUMN_NAME_DUE_DATE + TEXT_TYPE + COMMA_SEP +
COLUMN_NAME_STATUS + TEXT_TYPE + COMMA_SEP +
COLUMN_NAME_RATING + REAL_TYPE + COMMA_SEP +
COLUMN_NAME_AMOUNT + REAL_TYPE + ");";
public static final String DELETE_TABLE = "DROP TABLE IF EXISTS " + TABLE_NAME;
}
为:
public static abstract class TransactionTable implements BaseColumns {
public static final String TABLE_NAME = "transaction"; //?????
public static final String COLUMN_NAME_TITLE = "title";
public static final String COLUMN_NAME_PERSON = "person";
public static final String COLUMN_NAME_ROLE = "role";
public static final String COLUMN_NAME_DATE = "date";
public static final String COLUMN_NAME_DUE_DATE = "due_date";
public static final String COLUMN_NAME_STATUS = "status";
public static final String COLUMN_NAME_RATING = "rating";
public static final String COLUMN_NAME_AMOUNT = "amount";
public static final String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + " (" +
_ID + " INTEGER PRIMARY KEY," +
COLUMN_NAME_TITLE + TEXT_TYPE + COMMA_SEP +
COLUMN_NAME_PERSON + TEXT_TYPE + COMMA_SEP +
COLUMN_NAME_ROLE + TEXT_TYPE + COMMA_SEP +
COLUMN_NAME_DATE + TEXT_TYPE + COMMA_SEP +
COLUMN_NAME_DUE_DATE + TEXT_TYPE + COMMA_SEP +
COLUMN_NAME_STATUS + TEXT_TYPE + COMMA_SEP +
COLUMN_NAME_RATING + REAL_TYPE + COMMA_SEP +
COLUMN_NAME_AMOUNT + REAL_TYPE + ");";
public static final String DELETE_TABLE = "DROP TABLE IF EXISTS " + TABLE_NAME;
}
有谁知道为什么会这样?