-2

please help me i have a problem with my database .

here is my code

    private static final String DB_TABLE = "create table personn (personId integer primary key autoincrement, "+ "personName text not null, personAge text not null, "+ " personName text not null, " + " photoId text not null);";

and + this :

    @Override
public void onCreate(SQLiteDatabase db) {

    db.execSQL(DB_TABLE);

}

but while i want to insert or select th android gives me error :

Caused by: android.database.sqlite.SQLiteException: no such table: persons (code 1): , while compiling: SELECT personName, photoId, personAge FROM persons

White Druid
  • 295
  • 1
  • 12
  • that means your table is not created, remove semicolon from last in DBtable variable. – D.J Sep 18 '17 at 06:59
  • i try that to it dosent work – White Druid Sep 18 '17 at 07:00
  • and your table name is different, use same table name for creating and selecting. – D.J Sep 18 '17 at 07:00
  • 1
    After making the change(s) (correct the table name) you will need to either clear/delete the App's data or uninstall the App and then restart the App. In short the `onCreate` method only runs when the database is initially created. – MikeT Sep 18 '17 at 07:01

2 Answers2

1

You have made a spelling mistake while creating the person table. You have named it as "personn" instead of "persons".

0

The error is quite clear - there is no table named persons. Either fix your select to reference personn or your create statement to create a table named persons.

Mureinik
  • 297,002
  • 52
  • 306
  • 350