При попытке реализовать метод query выводит ошибку:
"no such table: ShopDB2table (code 1): , while compiling: SELECT * FROM ShopDB2table".
Вот код для метода:
private GoodsCursorWrapper queryGoods(String whereClause, String[] whereArgs) {
Cursor cursor = mSQLiteDatabase.query(
"ShopDB2table",
null,
whereClause,
whereArgs,
null,
null,
null
);
return new GoodsCursorWrapper(cursor);
}
Код для курсор-Раппера .
public class GoodsCursorWrapper extends CursorWrapper {
public GoodsCursorWrapper(Cursor cursor) {
super(cursor);
}
public Goods getGoods() {
int id = getInt(getColumnIndex(COLUMN_ID));
String titleOfGoods = getString(getColumnIndex(TITLE_OF_GOODS));
String price = getString(getColumnIndex(PRICE));
Goods goods = new Goods();
goods.setID(id);
goods.setTitleGoods(titleOfGoods);
goods.setPrice(price);
return goods;
}
}
Код, которым в приложение вставляется существующая база и ее таблица
public class ShopBaseHelper extends SQLiteOpenHelper {
private static final int VERSION = 1;
private static String DB_PATH = null;
private final Context myContext;
public static final String DATABASE_NAME = "databasesShopDB2.db";
public static final String TABLE_NAME = "ShopDB2table";
static final String COLUMN_ID = "_id";
static final String TITLE_OF_GOODS = "TitleOfGoods2";
static final String PRICE = "Price2";
private SQLiteDatabase mSQLiteDatabase;
public ShopBaseHelper(Context context) {
super(context, DATABASE_NAME, null, VERSION);
this.myContext = context;
this.DB_PATH = context.getApplicationInfo().dataDir + "/databases/";
try {
createDataBase();
} catch (IOException e) {
e.printStackTrace();
}
openDataBase();
}
public void createDataBase() throws IOException {
boolean dbExist = checkDataBase();
if (dbExist) {
} else {
this.getReadableDatabase();
try {
copyDataBase();
} catch (IOException e) {
throw new Error("Error copying database");
}
}
}
private boolean checkDataBase() {
File myPath = new File (DB_PATH + DATABASE_NAME);
return myPath.exists();
}
private void copyDataBase() throws IOException {
InputStream goodsInput = myContext.getAssets().open(DATABASE_NAME);
String outFileName = DB_PATH + DATABASE_NAME;
OutputStream goodsOutput = new FileOutputStream(outFileName);
byte[] buffer = new byte[1024];
int length;
while ((length = goodsInput.read(buffer)) > 0) {
goodsOutput.write(buffer, 0, length);
}
goodsOutput.flush();
goodsOutput.close();
goodsInput.close();
}
public void openDataBase() throws SQLException {
String bdPath = DB_PATH + DATABASE_NAME;
mSQLiteDatabase = SQLiteDatabase.openDatabase(bdPath, null, SQLiteDatabase.CREATE_IF_NECESSARY);
}
public synchronized void close() {
if (mSQLiteDatabase != null)
mSQLiteDatabase.close();
super.close();
}
@Override
public void onCreate(SQLiteDatabase db) {
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersuin) {
}}