0
public boolean insertData(int id_pedido, int id_item, String nome, int quantidade) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(COL_1_ITEM_ORDER, id_pedido);
contentValues.put(COL_2_ITEM_ORDER, id_item);
contentValues.put(COL_3_ITEM_ORDER, nome);
contentValues.put(COL_4_ITEM_ORDER, quantidade);
String sql = "SELECT preco FROM " + TABLE_PRECO + " WHERE id_item = " + id_item;
Cursor cursor = db.rawQuery(sql,null);
cursor.moveToFirst();
String preco_unitario = cursor.getString(cursor.getColumnIndex(COL_3_PRICES));
cursor.close();
double total = quantidade * Long.parseLong(preco_unitario);
contentValues.put(COL_5_ITEM_ORDER, preco_unitario);
contentValues.put(COL_6_ITEM_ORDER, total);
long result = db.insert(TABLE_ITEM_PEDIDO, null, contentValues);
if (result == -1) {
return false;
} else {
return true;
}
ERROR : android.database.Cursorindexoutofboundsexception: Index 0 requested, with a size of 0
Can someone please assist me? I’ve made several changes and nothing.
Can you tell which line is the error?
– Jorge B.