That’s the code getColumnIndex() displays with a red color.

I’m trying to add the orders that the user click to another activity so I used sqlite database
public List<Order> getCarts() {
SQLiteDatabase db = getReadableDatabase();
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
String[] sqlSelect = {"ProductName", "ProductId", "Quantity", "Price", "Discount"};
String sqlTable = "OrderDetail";
qb.setTables(sqlTable);
Cursor c = qb.query(db, sqlSelect, null, null, null, null, null);
final List<Order> result = new ArrayList<>();
if (c.moveToFirst()) {
do {
result.add(new Order(c.getString(c.getColumnIndex()),
c.getString(c.getColumnIndex("ProductName")),
c.getString(c.getColumnIndex("Quantity")),
c.getString(c.getColumnIndex("Price")),
c.getString(c.getColumnIndex("Discount"))
));
}while (c.moveToNext());
}
return result;
}
Order Class:
public class Order {
private String ProductId;
private String ProductName;
private String Quantity;
private String Price;
private String Discount;
public Order() {
}
public Order(String productId, String productName, String quantity, String price, String discount) {
ProductId = productId;
ProductName = productName;
Quantity = quantity;
Price = price;
Discount = discount;
}
}
>Solution :
First of all, you’re missing the column name in your first getColumnIndex().
Second, Android platform has added @IntRange annotations to these methods. getColumnIndex() returns an int from -1 up while getString() and similar require an int argument up from 0, and lint complains about that.
You can suppress it with @SuppressLint("range").
Or, since you’re defining the projection (column names) yourself, you can just hardcode the column indices as 0, 1, 2, … without using getColumnIndex() at all.