Hello I'm getting an OutOfBoundsExpection: Index 0 requested, with a size of 0. My database was working before.
Here is a snippet of the code:
MainActivity.db = new DatabaseHandler(ncontext);
MainActivity.db.addPokemon(new Pokedex(0, "Bulbasaur", "001", "Grass/Poison", "Lv 5",1));
//Crashes:
Log.d(tag,"This is drawable: "+ MainActivity.db.getPokemon(0,1).getPokemonImage());
//DataBase class
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_POKEMON, columns, KEY_ID + "=?" + " AND "
+ KEY_POKEMON_IMAGE + "=?", new String[] { String.valueOf(id),
String.valueOf(poke_image) }, null, null, null, null);
if ((cursor != null && cursor.moveToFirst()) ){
cursor.moveToNext();
cursor.close();
}
Log.d(Tag, "pre pokedex fetch");
Pokedex pokemon;
//CRASHES
Log.d("Database","1: " + Integer.parseInt(cursor.getString(0)));
// return pokemon
pokemon = new Pokedex(Integer.parseInt(cursor.getString(0)),
cursor.getString(1), cursor.getString(2), cursor.getString(3),
cursor.getString(4), Integer.parseInt(cursor.getString(5)));
Log.d(Tag, "getPokemon done");
return pokemon;
Any idea what is going wrong?
0 comments:
Post a Comment