Hello, I have a question, why I can consider information only from one database, and the second one seemed not to be created. In my application, the user clicks on the CardView in ResyclerView and, in an intent, the number of the pressed position is transmitted. So when a user clicks on the first item in ResyclerView, everything works as soon as he clicks on the second item, the studio writes an error: SQLiteException: no such table: AUTORATE. And if at the start of the application to immediately click on the second item, the reading will not happen either. Class in which the database is created:
public class MyDataBase { private DBOpenHelper dbOpenHelper; private SQLiteDatabase database; private static final String DB_NAME = "AutoRate"; private static final String TABLE_NAME = "AUTOCOLOR"; private static final String SECOND_TABLE_NAME = "AUTORATE"; public static final String NAME = "NAME"; public static final String DESCRIPTION = "DESCRIPTION"; public static final String PRICE = "PRICE"; private static final int DB_VERSION = 1; public MyDataBase(Context context) { dbOpenHelper = new DBOpenHelper(context); } public Cursor getAllItems(String tableName) { database = dbOpenHelper.getReadableDatabase(); return database.query(tableName, null, null, null, null, null, null); } public void close() { if (dbOpenHelper != null) dbOpenHelper.close(); if (database != null) database.close(); } public class DBOpenHelper extends SQLiteOpenHelper { public DBOpenHelper(Context context) { super(context, DB_NAME, null, DB_VERSION); } @Override public void onCreate(SQLiteDatabase db) { db.execSQL("CREATE TABLE " + SECOND_TABLE_NAME + " (_id INTEGER PRIMARY KEY AUTOINCREMENT, " + NAME + " TEXT, " + DESCRIPTION + " TEXT, " + PRICE + " INTEGER) ;"); insertService(db, "AUTORATE", "Шиномонтаж", "Замена четырех колес", 5000); insertService(db, "AUTORATE", "Кузовные работы", "Замена чего то там", 12000); insertService(db, "AUTORATE", "Диагностика", "Продиагностировать чего-нибудь", 4000); db.execSQL("CREATE TABLE " + TABLE_NAME + " (_id INTEGER PRIMARY KEY AUTOINCREMENT, " + NAME + " TEXT, " + DESCRIPTION + " TEXT, " + PRICE + " INTEGER) ;"); insertService(db, "AUTOCOLOR", "Шиномонтаж", "Замена четырех колес", 4000); insertService(db, "AUTOCOLOR", "Кузовные работы", "Замена чего то там", 10000); insertService(db, "AUTOCOLOR", "Диагностика", "Продиагностировать чего-нибудь", 3000); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } private void insertService(SQLiteDatabase db, String currentDataBaseName, String name, String description, int price) { ContentValues contentValues = new ContentValues(); contentValues.put(NAME, name); contentValues.put(DESCRIPTION, description); contentValues.put(PRICE , price); db.insert(currentDataBaseName, null, contentValues); } } } The code where from the intent gets the number of the pressed position on the ResyclerView:
@Override protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_auto_service_detail); Bundle bundle= getIntent().getExtras(); if(bundle != null){ Object o = bundle.get(EXTRA_SERVICE_NO); autoServiceNo = (Integer.parseInt(String.valueOf(o))); } tableName = AutoServiceInfo.autoServices[autoServiceNo].getName(); dataBase = new MyDataBase(this); Cursor cursor = dataBase.getAllItems(tableName); String[]from = new String[]{MyDataBase.NAME,MyDataBase.DESCRIPTION,MyDataBase.PRICE}; int[] to = new int[]{R.id.tvName, R.id.tvDescription, R.id.tvPrise}; cursorAdapter = new SimpleCursorAdapter(this, R.layout.item, cursor, from, to,0); listView = (ListView)findViewById(R.id.listViewPrise); listView.setAdapter(cursorAdapter);