I get an error when trying to insert into TABLE_EVENTS but no problem inserting/querying TABLE_CONTACTS. Here is my create string:
private static final String DATABASE_CREATE =
"create table "+ TABLE_CONTACTS + "( " + COLUMN_CONTACTS_LOOKUP
+ " text primary key, " + COLUMN_CONTACTS_ADDED
+ " real not null);" +
" create table "+ TABLE_EVENTS +"( "+ COLUMN_ID +" integer primary key autoincrement, "+
COLUMN_EVENTS_TITLE + " text not null, "+COLUMN_EVENTS_START_TIME+" real not null, "+
COLUMN_EVENTS_END_TIME+ " real, "+COLUMN_EVENTS_TYPE+" integer not null, "+COLUMN_EVENTS_START_LONG+" integer, "+
COLUMN_EVENTS_START_LAT+" integer);";
Called with
public void onCreate(SQLiteDatabase db){
db.execSQL(DATABASE_CREATE);
}
And my insert is
public long createEvent(String title, long start, long end, int type, int long_, int lat){
ContentValues initialValues = new ContentValues();
initialValues.put(COLUMN_EVENTS_TITLE, title);
initialValues.put(COLUMN_EVENTS_START_TIME, start);
initialValues.put(COLUMN_EVENTS_END_TIME, end);
initialValues.put(COLUMN_EVENTS_TYPE, type);
initialValues.put(COLUMN_EVENTS_START_LAT, lat);
initialValues.put(COLUMN_EVENTS_START_LONG, long_);
return mDb.insert(TABLE_EVENTS, null, initialValues);
}
This is because the
SQLiteDatabaseclass only allows oneCREATEstatement in yourDATABASE_CREATEstring. If you want to create more than one table, the trick is to prepare multiple creation strings, then call them one by one in youronCreatemethod:You’re getting an error because your events table was never created.