I added 2 new columns to my SQL lite Database but I get an SQL error as one of the new columns isn't being created. I've read other threads with similar error and double checked to make sure I'm spelling it right.
The problem seems to be on my onCreate as this is where the program is crashing but I can't seem to figure it out. I added the Player_Number and Team columns however the Player_Number isnt being created yet the Team one is.
Here's my code for the DBAdapter:
public class PlayerDbAdapter {
private static final String DATABASE_CREATE = "CREATE TABLE Players (_id integer primary key autoincrement, Player_Name text not null, Player_Position text not null, Player_Number text not null, Team text not null);";
private static final String DATABASE_NAME = "Score";
private static final String DATABASE_TABLE = "Players";
private static final int DATABASE_VERSION = 3;
public static final String KEY_BODY = "Player_Name";
public static final String KEY_ROWID = "_id";
public static final String KEY_TITLE = "Player_Position";
public static final String KEY_NUMBER = "Player_Number";
public static final String KEY_TEAM = "Team";
private static final String TAG = "PlayerDbAdapter";
private final Context mCtx;
private SQLiteDatabase mDb;
private DatabaseHelper mDbHelper;
public PlayerDbAdapter(Context paramContext)
{
this.mCtx = paramContext;
}
public void close()
{
this.mDbHelper.close();
}
public long createPlayers(String playerName, String playerPosition, String playerNumber, String team)
{
ContentValues localContentValues = new ContentValues();
localContentValues.put(KEY_BODY, playerName);
localContentValues.put(KEY_TITLE, playerPosition);
localContentValues.put(KEY_NUMBER, playerNumber);
localContentValues.put(KEY_TEAM, team);
try{
return this.mDb.insert("Players", null, localContentValues);
} catch (Exception e) {
Log.e("Juma", e.getMessage());
}
return 0;
}
Logcat
04-17 14:41:42.890: I/Database(407): sqlite returned: error code = 1, msg = table Players has no column named Player_Number
04-17 14:41:43.011: E/Database(407): Error inserting Player_Number=23 Team=Chester 1st Team (Men) Player_Position=Goalkeeper Player_Name=a
04-17 14:41:43.011: E/Database(407): android.database.sqlite.SQLiteException: table Players has no column named Player_Number: , while compiling: INSERT INTO Players(Player_Number, Team, Player_Position, Player_Name) VALUES(?, ?, ?, ?);
04-17 14:41:43.011: E/Database(407): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
04-17 14:41:43.011: E/Database(407): at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:92)
04-17 14:41:43.011: E/Database(407): at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:65)
04-17 14:41:43.011: E/Database(407): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:83)
04-17 14:41:43.011: E/Database(407): at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:41)
04-17 14:41:43.011: E/Database(407): at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:1149)
04-17 14:41:43.011: E/Database(407): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1549)
04-17 14:41:43.011: E/Database(407): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1422)
04-17 14:41:43.011: E/Database(407): at playerdatabase.PlayerDbAdapter.createPlayer(PlayerDbAdapter.java:46)
04-17 14:41:43.011: E/Database(407): at your.dissertation.project.SquadActivity$1.onClick(SquadActivity.java:53)
04-17 14:41:43.011: E/Database(407): at android.view.View.performClick(View.java:2485)
04-17 14:41:43.011: E/Database(407): at android.view.View$PerformClick.run(View.java:9080)
04-17 14:41:43.011: E/Database(407): at android.os.Handler.handleCallback(Handler.java:587)
04-17 14:41:43.011: E/Database(407): at android.os.Handler.dispatchMessage(Handler.java:92)
04-17 14:41:43.011: E/Database(407): at android.os.Looper.loop(Looper.java:123)
04-17 14:41:43.011: E/Database(407): at android.app.ActivityThread.main(ActivityThread.java:3647)
04-17 14:41:43.011: E/Database(407): at java.lang.reflect.Method.invokeNative(Native Method)
04-17 14:41:43.011: E/Database(407): at java.lang.reflect.Method.invoke(Method.java:507)
04-17 14:41:43.011: E/Database(407): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-17 14:41:43.011: E/Database(407): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-17 14:41:43.011: E/Database(407): at dalvik.system.NativeStart.main(Native Method)