Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android Android Data Persistence Using SQLite for Structured Data Creating a SQLite Table

ANOTHER 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!

AutoSQLiteHelper.java
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);
  }
}

STILL GETTING A BUMMER,

4 Answers

Dan Johnson
Dan Johnson
40,532 Points

Looks 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.

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_CAR_MODELS + " TEXT)";

@Override public void onCreate(SQLiteDatabase database) { database.execSQL(CREATE_CAR_MAKERS); database.execSQL(CREATE_CAR_MODELS); } }

Dan Johnson
Dan Johnson
40,532 Points

Looks 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.

GOT IT ANX......

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 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); } }

public 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); } }