-1

i am trying to create a sqlite table with with 2 columns, name id and last name; when i run my app it says "table TABLE_Names has no column named LastName" What am i doing wrong?

       private static final String CREATE_TABLE_Names =  "CREATE TABLE " + "TABLE_Names" +("
              + "NAME_Id" +" INTEGER PRIMARY KEY AUTOINCREMENT, "
              + "LastName"+ " TEXT, " +") ";




          public DataBaseWrapper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }





@Override
public void onCreate(SQLiteDatabase db) {
    // TODO Auto-generated method stub
    db.execSQL(CREATE_TABLE_Names);

}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    // TODO Auto-generated method stub
    db.execSQL("DROP TABLE IF EXISTS " + "TABLE_Names");
    this.onCreate(db);

}
Samantha
  • 199
  • 5
  • 15
  • 2
    Uninstall your app or wipe its data to remove the old database. See http://stackoverflow.com/questions/21881992/when-is-sqliteopenhelper-oncreate-onupgrade-run – laalto Jun 13 '14 at 19:04
  • Remove the `,` after `TEXT` – 323go Jun 13 '14 at 19:34

1 Answers1

1

Try this :

private static final String CREATE_TABLE_Names =  "CREATE TABLE " + "TABLE_Names" +("
              + "NAME_Id" +" INTEGER PRIMARY KEY AUTOINCREMENT, "
              + "LastName"+ " TEXT " +") ";

I removed the comma after TEXT. It is a syntax error in SQL.

tonystrawberry
  • 102
  • 1
  • 2
  • 12