# android.database.sqlite.SQLiteException: Cannot read from cursor: column 'price' has type REAL but expected INTEGER (code 0)

- **ID:** `android/sqlite-cursor-column-type-mismatch`
- **Domain:** android
- **Category:** data_error
- **Error Code:** `SQLiteException code 0`
- **Verification:** ai_generated
- **Fix Rate:** 92%

## Root Cause

Cursor attempts to read a REAL column as INTEGER via getInt(), causing type mismatch in SQLite's dynamic typing system.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Android 11 (API 30) | active | — | — |
| Android 12 (API 31) | active | — | — |
| Android 13 (API 33) | active | — | — |

## Workarounds

1. **Use `cursor.getDouble(cursor.getColumnIndexOrThrow("price"))` instead of getInt() to read REAL columns correctly.** (95% success)
   ```
   Use `cursor.getDouble(cursor.getColumnIndexOrThrow("price"))` instead of getInt() to read REAL columns correctly.
   ```
2. **In Room, annotate the field as `Double` (not Int) in the entity class: `@ColumnInfo(name = "price") val price: Double`** (92% success)
   ```
   In Room, annotate the field as `Double` (not Int) in the entity class: `@ColumnInfo(name = "price") val price: Double`
   ```
3. **Use `cursor.getType(columnIndex)` to check the type before reading: if type == Cursor.FIELD_TYPE_FLOAT, use getDouble(); else getInt().** (85% success)
   ```
   Use `cursor.getType(columnIndex)` to check the type before reading: if type == Cursor.FIELD_TYPE_FLOAT, use getDouble(); else getInt().
   ```

## Dead Ends

- **Cast the column value to int in SQL query: `CAST(price AS INTEGER)`** — This truncates decimals, losing precision; the real fix is to read as getDouble(). (70% fail)
- **Change column type in CREATE TABLE to INTEGER** — SQLite is dynamically typed; the column type only affects affinity, not actual stored values. Existing data remains REAL. (85% fail)
- **Use getString() and parse to int** — Parsing '12.99' to int throws NumberFormatException or truncates incorrectly. (90% fail)
