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 trial
james white
78,399 PointsUsing this snippet of a subclassed SQLiteOpenHelper, modify creates table code to add a TEXT field "COMPANY_NAME"
Android Data Persistence Creating an SQLite Table Challenges 1 thru 3
I had no idea how to add a text field to a Create Table string for SQLite!
However, after several hours of going through the SQLite documentation
(the Treehouse videos were only vaguely useful at best, talking about MEMES_TABLEs -- not CREATE_CAR_MAKERS tables),
I finally came up with some randomly permutated (trial and error) code, which (after many attempts and java parsing errors) finally (luckily) seemed to pass:
public class AutoSQLiteHelper extends SQLiteOpenHelper {
public static final String COMPANY_NAME = "NAME";
public static final String CREATE_CAR_MAKERS =
"CREATE TABLE CAR_MAKERS ( _id INTEGER PRIMARY KEY, COMPANY_NAME TEXT)";
public static final String CAR_NAME = "CARNAME";
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);
}
}
Even searching for SQLiteOpenHelper failed to give an hint what I was supposed to do and the video before the challenge didn't spell out anything for AutoSQLiteHelper, so good luck to anyone who tries to get something out of this challenge without being an advanced expert in SQLite,
(which this Android Data Persistence course doesn't accomplish).
1 Answer
Kristian Terziev
28,449 PointsYou didn't have to assing COMPANY_NAME and CAR_NAME variables with anything since you're using them as strings on the next line (so you have 2 lines that are not necessary). So all you needed to do, was add "COMPANY_NAME TEXT" in the brackets of the CREATE_CAR_MAKERS String and that's it. Just three words. All this was covered in 2 videos before the challenge where Evan first hardcoded the strings and then replaced them with initialized variables. Hope that helps with the confusion :)
MUZ140157 Cleopas Tekwani
9,474 PointsMUZ140157 Cleopas Tekwani
9,474 Pointsthanx James