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 trialChad Johnson
10,936 PointsNot sure why my code is not correct, it is not accepting format in previous video
Using this following snippet of a subclassed SQLiteOpenHelper, modify the code that creates the table to also add a TEXT field called "COMPANY_NAME". The code I am attempting is similar to the previous video, and it is not accepting it. Not sure where I'm going wrong
public class AutoSQLiteHelper extends SQLiteOpenHelper {
public static final String CREATE_CAR_MAKERS =
"CREATE TABLE CAR_MAKERS (_id INTEGER PRIMARY KEY AUTOINCREMENT + COLUMN_COMPANY_NAME + " TEXT")";
@Override
public void onCreate(SQLiteDatabase database) {
database.execSQL(CREATE_CAR_MAKERS);
}
}
2 Answers
James Simshaw
28,738 PointsHello,
You currently do not have a variable named COLUMN_COMPANY_NAME that would be inserting the column name into the creation string. Your string also needs a little help, you currently have:
"CREATE TABLE CAR_MAKERS (_id INTEGER PRIMARY KEY AUTOINCREMENT + COLUMN_COMPANY_NAME + " TEXT")";
which is missing a comma between elements that you're adding, and you didn't end the string before the first +, as well as having an extra " before the ). After those fixes it should look more like
"CREATE TABLE CAR_MAKERS (_id INTEGER PRIMARY KEY AUTOINCREMENT, " + COLUMN_COMPANY_NAME + " TEXT)";
where you have previously created a string COLUMN_COMPANY_NAME which holds what you want to call the column for the company name.
Herbert Chipendo
8,544 PointsLate but this worked for me.
public class AutoSQLiteHelper extends SQLiteOpenHelper {
public static final String COLUMN_COMPANY_NAME = "name"; public static final String CREATE_CAR_MAKERS = "CREATE TABLE CAR_MAKERS (_id INTEGER PRIMARY KEY AUTOINCREMENT, " + "COMPANY_NAME TEXT)";
@Override public void onCreate(SQLiteDatabase database) { database.execSQL(CREATE_CAR_MAKERS); } }