Я создал функцию в DatabaseOpenHelper, чтобы получить весь список продуктов моей базы данных, но у меня есть ошибка java .lang.IllegalStateException: неверные таблицы
, хотя в моей базе данных есть таблица продуктов
Это моя функция: DatabaseOpenHelper
public class DatabaseOpenHelper extends SQLiteAssetHelper {
private static final String DATABASE_NAME="SKIP.db";
private static final int DATABASE_VERSION=1;
//Constructor
public DatabaseOpenHelper(Context context){
super (context, DATABASE_NAME,null,DATABASE_VERSION);
}
//Function get all productlist
public List<productlist> getProductlist()
{
SQLiteDatabase db = getReadableDatabase();
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
//Make sure the same column name in yor database table
String[] sqlSelect = {"product_name","product_supp","product_category","product_desc"};
String tableName = "products"; // make sure this is your table name
qb.getTables();
Cursor cursor = qb.query(db,sqlSelect,null, null,null,null,null);
List<productlist> result = new ArrayList<>();
if(cursor.moveToNext())
{
do{
productlist productlist = new productlist();
productlist.setId(cursor.getInt(cursor.getColumnIndex("product_id")));
productlist.setProduct_name(cursor.getString(cursor.getColumnIndex("product_name")));
productlist.setProduct_supp(cursor.getString(cursor.getColumnIndex("product_supp")));
productlist.setProduct_category(cursor.getString(cursor.getColumnIndex("product_category")));
productlist.setProduct_desc(cursor.getString(cursor.getColumnIndex("product_desc")));
result.add(productlist);
} while (cursor.moveToNext());
}
return result;
}
Это ошибка, когда я пытался запустить приложение
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.skip, PID: 7443
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.skip/com.example.skip.ProductView}: java.lang.IllegalStateException: Invalid tables
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3260)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3396)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2009)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7319)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:934)
Caused by: java.lang.IllegalStateException: Invalid tables
at android.database.sqlite.SQLiteDatabase.findEditTable(SQLiteDatabase.java:1100)
at android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:517)
at android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:392)
at com.example.skip.DatabaseOpenHelper.getProductlist(DatabaseOpenHelper.java:45)
at com.example.skip.ProductView.onCreate(ProductView.java:105)
at android.app.Activity.performCreate(Activity.java:7783)
at android.app.Activity.performCreate(Activity.java:7772)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3235)
Это моя таблица базы данных
БАЗА ДАННЫХ