Estoy intentando poner 2 bases de datos a la vez en mi aplicación y no sé por qué, ¿ qué estoy haciendo mal ? Pongo mis dos bases de datos y los cambios que he usado para referirme a una y a otra ( cambios variables y demás) :
La que sí funciona :
public class BaseHelper extends SQLiteOpenHelper {
String tabla ="CREATE TABLE Notas(Id INTEGER PRIMARY KEY AUTOINCREMENT, Primero INTEGER, Segundo INTEGER)";
public BaseHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
super(context, name, factory, version);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(tabla);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
// Como lo llamo :
public void cargar () {
BaseHelper baseHelper = new BaseHelper (this,"DEMODB",null,1);
SQLiteDatabase db = baseHelper.getReadableDatabase();
if(db!=null){
Cursor c = db.rawQuery("SELECT * FROM Notas ORDER BY Primero DESC LIMIT 5",null);
final int cantidad = c.getCount();
int i=0;
String[] arreglo = new String [cantidad];
if(c.moveToFirst()){
do{
String linea = c.getInt(0)+" "+ c.getInt(1)+" Clicks";
arreglo[i] = linea;
i++;
}while(c.moveToNext());
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,arreglo);
ListView lista = (ListView) findViewById(R.id.listView);
lista.setAdapter(adapter);
La que no funciona :
public class BaseHelper2 extends SQLiteOpenHelper {
String tabla2 ="CREATE TABLE Notas2(Id INTEGER PRIMARY KEY AUTOINCREMENT, Primero INTEGER, Segundo INTEGER)";
public BaseHelper2(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
super(context, name, factory, version);
}
@Override
public void onCreate(SQLiteDatabase db2) {
db2.execSQL(tabla2);
}
@Override
public void onUpgrade(SQLiteDatabase db2, int oldVersion, int newVersion) {
}
}
// Como la llamo:
public void cargar () {
BaseHelper baseHelper = new BaseHelper (this,"DEMODB",null,1);
SQLiteDatabase db2 = baseHelper.getReadableDatabase();
if(db2!=null){
Cursor c2 = db2.rawQuery("SELECT * FROM Notas2 ORDER BY Primero DESC LIMIT 5",null);
final int cantidad2 = c2.getCount();
int i=0;
String[] arreglo2 = new String [cantidad2];
if(c2.moveToFirst()){
do{
String linea2 = c2.getInt(0)+" "+ c2.getInt(1)+" Clicks";
arreglo2[i] = linea2;
i++;
}while(c2.moveToNext());
}
ArrayAdapter<String> adapter2 = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,arreglo2);
ListView lista2 = (ListView) findViewById(R.id.listView2);
lista2.setAdapter(adapter2);
He intentado cambiar variables , eso es posible? ¿ Es posible que sea por el nombre al ponerle un "2" ya que debe llamarse si o si "BaseHelper" ?