vendredi 27 mars 2015

Query (The query is good!!) in Listview and DialogFragment

Hi guys i have a huge problem that in cannot reoslve... it's simple, y have a ListView and when y click in a one item of the ListView I get the "Rubro" of that item and it's fine...the problem is that I have a method that I do a query of comapre this Rubro and get a Long att form the table but, the query dont work!! but i know that the query is good because I prove it whit the DB Brwoser for SQLite!! so here is the code where i call the method:



public void onClick(DialogInterface dialog, int id) {

TextView selectR = (TextView) view.findViewById(R.id.Rubro);
TextView selectV = (TextView) view.findViewById(R.id.Valor);
Long ac = db.Buscar_Rubro(selectR.getText().toString()); //THIS IS THE METHOD!
EditText r = (EditText) dialogV.findViewById(R.id.Mod);
Long Sum = Long.parseLong(r.getText().toString());

db.ModRubros(Long.parseLong(selectV.getText().toString()),ac,Sum);


Cursor cT = db.ListarRubros();
//RefreshRubros(cT, from, to);
}


And here is the Method:


public long Buscar_Rubro(String Rubro){



SQLiteDatabase DB = database.getReadableDatabase();


String Query ="SELECT " + Database.ValorActrual + " FROM "+ Database.Taba_Rubros + " WHERE " + Database.Rubro + " LIKE '"+ Rubro +"'" ;
Cursor c = DB.rawQuery(Query,null);

Long ac = c.getLong(1);
return ac;
}


Please help me! I lost all the day to correct this!


PD: This is the error that i get but it's obvios becuae the query dont work!


android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1


Aucun commentaire:

Enregistrer un commentaire