0

This DBHelper code is working in all version but not working android version 9 . I found the answer in these two questions, but I'm a beginner and I can't apply it.

A pre-populated database does not work at API 28 throws "no such table" exception

Android P - 'SQLite: No Such Table Error' after copying database from assets in android version 9

public class DataBase_artifacts extends SQLiteOpenHelper {

public static final String DBNAME = "data_artifacts.db";
public static final String DBLOCATION = "/data/data/egyking.ancientgreece/databases/";
private Context mContext;
private SQLiteDatabase mDatabase;

public DataBase_artifacts(Context context) {
    super(context, DBNAME, null, 1);
    this.mContext = context;
}

@Override
public void onCreate(SQLiteDatabase db) {

}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

}

public void openDatabase() {
    String dbPath = mContext.getDatabasePath(DBNAME).getPath();
    if(mDatabase != null && mDatabase.isOpen()) {
        return;
    }
    mDatabase = SQLiteDatabase.openDatabase(dbPath, null, SQLiteDatabase.OPEN_READWRITE);
}

public List<item> getListProduct() {
    item product = null;
    List<item> productList = new ArrayList<>();
    openDatabase();
    Cursor cursor = mDatabase.rawQuery("SELECT * FROM tablo", null);
    cursor.moveToFirst();
    while (!cursor.isAfterLast()) {
        product = new item(cursor.getInt(0), cursor.getString(1), cursor.getString(2), cursor.getString(3));
        productList.add(product);
        cursor.moveToNext();
    }
    cursor.close();
    if(mDatabase!=null) {
        mDatabase.close();
    }
    return productList;
}

}

0 Answers0