-1
私のinv.dbには以下の内容があります修正方法アンドロイドのカーソル初期化エラー?
select * from inventory;
id|name|supplier|quanity|price
1|Product 1|Wallmart|10|50
2|Product 1|Wallmart|10|50
は、しかし、私はエラー
Failed to read row 0, column -1 from a CursorWindow which has 2 rows, 3 columns.
Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
を得る。しかし、IDを除く4つの列があります。
// Find the columns of pet attributes that we're interested in
int nameColumnIndex = cursor.getColumnIndex(InventoryContract.InventoryEntry.COLUMN_PRO_NAME);
int priceColumnIndex = cursor.getColumnIndex(InventoryContract.InventoryEntry.COLUMN_PRO_PRICE);
int quanColumnIndex = cursor.getColumnIndex(InventoryContract.InventoryEntry.COLUMN_PRO_QUAN);
int supColumnIndex = cursor.getColumnIndex(InventoryContract.InventoryEntry.COLUMN_PRO_SUP);
// Read the pet attributes from the Cursor for the current pet
String petName = cursor.getString(nameColumnIndex);
String price = cursor.getString(priceColumnIndex);
String quantity = cursor.getString(quanColumnIndex); // produces error
ここで何が間違っているのかわかりません。私は、コード
実際には5つの列がありますが、アンドロイドはID、名前、価格の3つのみを表示しています。しかし、ターミナルでコマンドを実行すると、私はすべてを見ることができます。列名はすべて正しいです。 Ivは手作業で値3と4を添えてエラーを生成しました – Xera12
あなたはcursor.getColumnNamesを試しましたか? –
_id、名前、および価格を列名としてログに出力します。しかし、表スキーマはCREATE TABLEインベントリーです(_ID INTEGER PRIMARY KEY AUTOINCREMENT、TEXT NOT NULL、サプライヤーTEXT、数量INTEGER NOT NULL DEFAULT 0、価格INTEGER NOT NULL DEFAULT 0)。 – Xera12