Here is my code of the DataBase class. I don't understand why I'm not able to create the table articles. Error message says "no such table:articles(code1):,while compiling: select * from articles". I'm totally clueless why is this happening. Please helm me solve this problem.
class DataBase extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "MyDB.db";
public static final String ARTICLES_TABLE_NAME = "articles";
public static final String ARTICLES_COLUMN_ID = "id";
private static final String ARTICLES_COLUMN_NAME = "name";
public static final String ARTICLES_COLUMN_PRICE = "price";
public static final String COSTUMER_TABLE_NAME = "costumers";
public static final String COSTUMER_COLUMN_ID = "id";
public static final String COSTUMER_COLUMN_NAME = "name";
public static final String COSTUMER_COLUMN_PHONE = "phone";
//private HashMap hp;
DataBase(Context context) {
super(context, DATABASE_NAME, null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(
"create table articles " +
"(id integer primary key, name text, price text)");
db.execSQL(
"create table costumers " +
"(id integer primary key, name text,phone text)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS articles");
db.execSQL("DROP TABLE IF EXISTS costumers");
onCreate(db);
}
boolean insertArticle(String name, String price) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put("name", name);
contentValues.put("price", price);
db.insert("articles", null, contentValues);
return true;
}
ArrayList<String> getAllArticles() {
ArrayList<String> array_list = new ArrayList<String>();
//hp = new HashMap();
SQLiteDatabase db = this.getReadableDatabase();
Cursor res = db.rawQuery( "select * from articles", null );
res.moveToFirst();
while(!res.isAfterLast()){
array_list.add(res.getString(res.getColumnIndex(ARTICLES_COLUMN_NAME)));
res.moveToNext();
}
return array_list;
}
}