Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAdlight Sibanda
5,701 PointsANOTHER CREATE STATEMENT
Next, add another create statement called CREATE_CAR_MODELS that is public static final. Give it a primary key called _id and a TEXT field called CAR_NAME. The primary key should autoincrement!
public class AutoSQLiteHelper extends SQLiteOpenHelper {
public static final String COLUMN_COMPANY_NAME = "COMPANY_NAME";
public static final String COLUMN_CAR_MODELS = "CAR_MODELS";
public static final String CREATE_CAR_MAKERS =
"CREATE TABLE CAR_MAKERS (_id INTEGER PRIMARY KEY AUTOINCREMENT, " + COLUMN_COMPANY_NAME + " TEXT)";
public static final String CREATE_CAR_MODELS =
"CREATE TABLE CAR_MODELS (_id INTEGER PRIMARY KEY AUTOINCREMENT, " + COLUMN_CREATE_CAR_MODELS + " TEXT)";
@Override
public void onCreate(SQLiteDatabase database) {
database.execSQL(CREATE_CAR_MAKERS);
database.execSQL(CREATE_CAR_MODELS);
}
}
4 Answers
Dan Johnson
40,533 PointsLooks like just a mix up with constants:
// COLUMN_CREATE_CAR_MODELS -> COLUMN_CAR_MODELS
"CREATE TABLE CAR_MODELS (_id INTEGER PRIMARY KEY AUTOINCREMENT, " + COLUMN_CAR_MODELS + " TEXT)";
Everything else looks fine.
Adlight Sibanda
5,701 Pointspublic class AutoSQLiteHelper extends SQLiteOpenHelper { public static final String COLUMN_COMPANY_NAME = "COMPANY_NAME"; public static final String COLUMN_CAR_MODELS = "CAR_MODELS";
public static final String CREATE_CAR_MAKERS = "CREATE TABLE CAR_MAKERS (_id INTEGER PRIMARY KEY AUTOINCREMENT, " + COLUMN_COMPANY_NAME + " TEXT)";
public static final String CREATE_CAR_MODELS =
"CREATE TABLE CAR_MODELS (_id INTEGER PRIMARY KEY AUTOINCREMENT, " + COLUMN_CAR_MODELS + " TEXT)";
@Override public void onCreate(SQLiteDatabase database) { database.execSQL(CREATE_CAR_MAKERS); database.execSQL(CREATE_CAR_MODELS); } }
Dan Johnson
40,533 PointsAdded code tags.
Dan Johnson
40,533 PointsLooks like I missed the value of COLUMN_CAR_MODELS the first time, it should be assigned "CAR_NAME"
instead of "CAR_MODELS"
. You may want to rename the constant to reflect that though it won't matter either way.
Adlight Sibanda
5,701 PointsGOT IT ANX......
Lester Rusike
13,206 Pointspublic class AutoSQLiteHelper extends SQLiteOpenHelper { public static final String COLUMN_COMPANY_NAME = "COMPANY_NAME"; public static final String COLUMN_CAR_MODELS = "CAR_MODELS"; public static final String CAR_NAME = "CAR_NAME";
public static final String CREATE_CAR_MAKERS = "CREATE TABLE CAR_MAKERS (_id INTEGER PRIMARY KEY AUTOINCREMENT, " + COLUMN_COMPANY_NAME + " TEXT)";
public static final String CREATE_CAR_MODELS = "CREATE TABLE CAR_MODELS (_id INTEGER PRIMARY KEY AUTOINCREMENT, " + CAR_NAME + " TEXT)";
@Override public void onCreate(SQLiteDatabase database) { database.execSQL(CREATE_CAR_MAKERS); database.execSQL(CREATE_CAR_MODELS); } }
TERRENCE MAVHUNGA
6,053 Pointspublic class AutoSQLiteHelper extends SQLiteOpenHelper {
public static final String COMPANY_NAME = "COMPANY_NAME"; public static final String COLUMN_CAR_MODELS = "CAR_MODELS"; public static final String CAR_NAME = "CAR_NAME";
public static final String CREATE_CAR_MAKERS = "CREATE TABLE CAR_MAKERS (id INTEGER PRIMARY KEY AUTOINCREMENT,"+COMPANY_NAME+"TEXT)";
public static final String CREATE_CAR_MODELS = "CREATE TABLE CAR_MODELS (_id INTEGER PRIMARY KEY AUTOINCREMENT, " + CAR_NAME +" TEXT)";
@Override public void onCreate(SQLiteDatabase database) { database.execSQL(CREATE_CAR_MAKERS); database.execSQL(CREATE_CAR_MODELS); } }
Adlight Sibanda
5,701 PointsAdlight Sibanda
5,701 PointsSTILL GETTING A BUMMER,