I'm trying to access the database in local to get the list of all the plays and I get the error SQLiteException: no such column: comments (code 1) :, while compiling
I've been using the debugger and the error jumps just at the moment you try to create the cursor:
Method that makes the query
public List<Jugada> getAllJugadas() {
// Lista que almacenara el resultado
List<Jugada> jugadasList = new ArrayList<Jugada>();
//hacemos una query porque queremos devolver un cursor
Cursor cursor = db.query(helper.TABLE_NAME, columnas,
null, null, null, null, null);
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
final Jugada jugada = new Jugada();
jugada.setNombre(cursor.getString(1));
jugada.setImagen(cursor.getString(2));
jugada.setComentarios(cursor.getString(3));
jugadasList.add(jugada);
cursor.moveToNext();
}
cursor.close();
// Una vez obtenidos todos los datos y cerrado el cursor, devolvemos la
// lista.
return jugadasList;
}
Class that creates the DB
public class BDHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "jugadas.db";
private static final int VERSION = 1;
public static final String TABLE_NAME = "jugadas";
public static final String COLUMN_ID = "_id";
public static final String COLUMN_NOMBRE = "nombre";
public static final String COLUMN_IMGEN = "imagen";
public static final String COLUMN_COMENTARIOS = "comentarios";
/** Script para la creación de la base de datos **/
private static final String DATABASE_CREATE = "create table if not exists " + TABLE_NAME + "( " +
COLUMN_ID + " integer primary key autoincrement, " +
COLUMN_NOMBRE + " text not null, " +
COLUMN_IMGEN + " text not null, " +
COLUMN_COMENTARIOS + " text not null )";
/** Script para la eliminación de la base de datos **/
private static final String DATABASE_DROP = "drop table if exists " + TABLE_NAME;
public BDHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
super(context, DATABASE_NAME, factory, VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(DATABASE_CREATE);
try {
cargaJugadas(db);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private void cargaJugadas(SQLiteDatabase db) throws IOException {
File archivo = new File("jugadas_ataque.txt");
FileReader reader = new FileReader(archivo);
BufferedReader br = new BufferedReader(reader);
String linea;
String expr;
while((linea=br.readLine())!=null) {
String[] campos = linea.split(",");
expr = "INSERT INTO " + TABLE_NAME + " (" + campos[0] + ", " + campos[1] + ", " + campos[2];
db.execSQL(expr);
}
reader.close();
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL(DATABASE_DROP);
this.onCreate(db);
}
}
I have looked at many questions of the style and trying the solutions of the others I have not gotten that functions. Any ideas? Thanks in advance