Okay, here’s the situation: I’ve created a class extending Android’s SQLOpenHelper class. I’ve also implemented the required methods, onCreate and onUpgrade, to initialize tables and to drop the current tables and then re-create new ones respectively.
The tables were successfully created but when I tried to call a method to insert a new record to the database LogCat gave me this instead:
06-17 21:31:19.907: I/SqliteDatabaseCpp(561): sqlite returned: error code = 1, msg = table calendarEvents has no column named colour, db=/data/data/stub.binusitdirectorate.calendar/databases/calendarSQLite
I’ve done some search regarding this problem. Most of the answers suggested to re-install the app and repeat the process. Done, but still no success.
Here’s my SQLiteOpenHelper onCreate method:
public void onCreate(SQLiteDatabase db) {
String CREATE_EVENTS_TABLE = "CREATE TABLE " + EVENTS_TABLE + "("
+ KEY_EVENTS_TYPE_ID + " TEXT PRIMARY KEY,"
+ KEY_EVENTS_TYPE_NAME + " TEXT," + KEY_EVENTS_NAME + " TEXT,"
+ KEY_EVENTS_COLOR + "TEXT," + KEY_EVENTS_START_DATE + "DATE,"
+ KEY_EVENTS_END_DATE + "TEXT" + ")"
db.execSQL(CREATE_EVENTS_TABLE);
}
And here’s my method for inserting new records:
public void addEventsList(ArrayList<CalendarEventData> lstCalendarEvents) {
SQLiteDatabase db = this.getWritableDatabase();
if (lstCalendarEvents != null && db != null) {
for (int i = 0; i < lstCalendarEvents.size(); i++) {
ContentValues values = new ContentValues();
values.put(KEY_EVENTS_TYPE_ID, lstCalendarEvents.get(i)
.getEventTypeId());
values.put(KEY_EVENTS_TYPE_NAME, lstCalendarEvents.get(i)
.getEventTypeName());
values.put(KEY_EVENTS_NAME, lstCalendarEvents.get(i)
.getEventName());
values.put(KEY_EVENTS_COLOR, lstCalendarEvents.get(i)
.getColour());
values.put(KEY_EVENTS_START_DATE, DateUtils
.getFormattedDateString(lstCalendarEvents.get(i)
.getStartDateTime(), dateFormat));
values.put(KEY_EVENTS_END_DATE, DateUtils
.getFormattedDateString(lstCalendarEvents.get(i)
.getEndDateTime(), dateFormat));
db.insert(EVENTS_TABLE, null, values);
}
db.close();
}
}
I’m fairly new to Android and was using this tutorial as a guide.
Thanks in advance! 🙂
This part of your create statement might cause problems
You are missing a space before TEXT everywhere 🙂