I've been trying to reference the old code to create a table. I changed or the key/column names for the new table and everything was working fine. However, when I tried to change the name from "expense" (from the old code) to "transaction" (new code). I got
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);
All I did was change the TABLE_NAME from:
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;
}
to:
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;
}
Anyone knows why this is happening?
Aucun commentaire:
Enregistrer un commentaire