user3078867 user3078867 - 3 months ago 8
Java Question

SQLiteException no such column : plus (code 1)

Adding more columns to a database that already worked (plus and minus were added). I've looked at previous answers but I can't for the life of me find an error in my syntax.

private static final String TAG = "DBAdapter";

// DB Fields
public static final String KEY_ROWID = "_id";
public static final int COL_ROWID = 0;
/*
* CHANGE 1:
*/
// TODO: Setup your fields here:
public static final String KEY_NUMBER = "number";
public static final String KEY_LASTNAME = "lastname";
public static final String KEY_FIRSTNAME = "firstname";
public static final String KEY_POSITION = "position";
public static final String KEY_TIMEONICE = "timeonice";
public static final String KEY_PLUS = "plus";
public static final String KEY_MINUS = "minus";

// TODO: Setup your field numbers here (0 = KEY_ROWID, 1=...)
public static final int COL_NUMBER = 1;
public static final int COL_LASTNAME = 2;
public static final int COL_FIRSTNAME = 3;
public static final int COL_POSITION = 4;
public static final int COL_TIMEONICE = 5;
public static final int COL_PLUS = 6;
public static final int COL_MINUS = 7;



public static final String[] ALL_KEYS = new String[] {KEY_ROWID, KEY_NUMBER, KEY_LASTNAME, KEY_FIRSTNAME, KEY_POSITION, KEY_TIMEONICE,KEY_PLUS,KEY_MINUS};

// DB info: it's name, and the table we are using (just one).
public static final String DATABASE_NAME = "HOCKEY.db";
public static final String DATABASE_TABLE = "mainTable";
// Track DB version if a new version of your app changes the format.
public static final int DATABASE_VERSION = 7;

private static final String DATABASE_CREATE_SQL =
"create table " + DATABASE_TABLE
+ " (" + KEY_ROWID + " integer primary key autoincrement, "

/*
* CHANGE 2:
*/
// TODO: Place your fields here!
// + KEY_{...} + " {type} not null"
// - Key is the column name you created above.
// - {type} is one of: text, integer, real, blob
// (http://www.sqlite.org/datatype3.html)
// - "not null" means it is a required field (must be given a value).
// NOTE: All must be comma separated (end of line!) Last one must have NO comma!!
+ KEY_NUMBER + " integer not null,"
+ KEY_LASTNAME + " string not null,"
+ KEY_FIRSTNAME + " string not null,"
+ KEY_POSITION + " string not null,"
+ KEY_TIMEONICE + " string"
+ KEY_PLUS + " integer,"
+ KEY_MINUS + " integer"

// Rest of creation:
+ ");";


Log cat


01-01 21:55:16.971: E/AndroidRuntime(3476): Process: com.example.timeonice, PID: 3476
01-01 21:55:16.971: E/AndroidRuntime(3476): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.timeonice/com.example.timeonice.MainActivity}: android.database.sqlite.SQLiteException: no such column: plus (code 1): , while compiling: SELECT DISTINCT _id, number, lastname, firstname, position, timeonice, plus, minus FROM mainTable
01-01 21:55:16.971: E/AndroidRuntime(3476): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
01-01 21:55:16.971: E/AndroidRuntime(3476): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
01-01 21:55:16.971: E/AndroidRuntime(3476): at android.app.ActivityThread.access$800(ActivityThread.java:135)
01-01 21:55:16.971: E/AndroidRuntime(3476): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
01-01 21:55:16.971: E/AndroidRuntime(3476): at android.os.Handler.dispatchMessage(Handler.java:102)
01-01 21:55:16.971: E/AndroidRuntime(3476): at android.os.Looper.loop(Looper.java:136)
01-01 21:55:16.971: E/AndroidRuntime(3476): at android.app.ActivityThread.main(ActivityThread.java:5017)
01-01 21:55:16.971: E/AndroidRuntime(3476): at java.lang.reflect.Method.invokeNative(Native Method)
01-01 21:55:16.971: E/AndroidRuntime(3476): at java.lang.reflect.Method.invoke(Method.java:515)
01-01 21:55:16.971: E/AndroidRuntime(3476): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
01-01 21:55:16.971: E/AndroidRuntime(3476): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
01-01 21:55:16.971: E/AndroidRuntime(3476): at dalvik.system.NativeStart.main(Native Method)
01-01 21:55:16.971: E/AndroidRuntime(3476): Caused by: android.database.sqlite.SQLiteException: no such column: plus (code 1): , while compiling: SELECT DISTINCT _id, number, lastname, firstname, position, timeonice, plus, minus FROM mainTable
01-01 21:55:16.971: E/AndroidRuntime(3476): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
01-01 21:55:16.971: E/AndroidRuntime(3476): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
01-01 21:55:16.971: E/AndroidRuntime(3476): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
01-01 21:55:16.971: E/AndroidRuntime(3476): at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
01-01 21:55:16.971: E/AndroidRuntime(3476): at android.database.sqlite.SQLiteProgram.(SQLiteProgram.java:58)
01-01 21:55:16.971: E/AndroidRuntime(3476): at android.database.sqlite.SQLiteQuery.(SQLiteQuery.java:37)
01-01 21:55:16.971: E/AndroidRuntime(3476): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
01-01 21:55:16.971: E/AndroidRuntime(3476): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314)
01-01 21:55:16.971: E/AndroidRuntime(3476): at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1161)
01-01 21:55:16.971: E/AndroidRuntime(3476): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1032)
01-01 21:55:16.971: E/AndroidRuntime(3476): at com.example.timeonice.DBAdapter.getAllRows(DBAdapter.java:159)
01-01 21:55:16.971: E/AndroidRuntime(3476): at com.example.timeonice.DBAdapter.deleteAll(DBAdapter.java:146)
01-01 21:55:16.971: E/AndroidRuntime(3476): at com.example.timeonice.MainActivity.onCreate(MainActivity.java:135)
01-01 21:55:16.971: E/AndroidRuntime(3476): at android.app.Activity.performCreate(Activity.java:5231)
01-01 21:55:16.971: E/AndroidRuntime(3476): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
01-01 21:55:16.971: E/AndroidRuntime(3476): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)

Answer

You missed a comma

+ KEY_TIMEONICE + " string, " // <-- Here.