2017-06-08 14 views
-2

これは、テーブルの列を設定する契約クラスからコードAndroidのSQLiteのgetColumnIndex

public static final String _ID = BaseColumns._ID; 
    public static final String TABLE_NAME = "tools"; 
    public static final String COLUMN_TOOL_TYPE = "type"; 
    public static final String COLUMN_COST = "cost"; 
    public static final String COLUMN_IN_STOCK = "in_stock"; 
    public static final String COLUMN_STOCK_LEVEL = "stock_quantity"; 
    public static final String COLUMN_PICTURE = "picture"; 

あるデータベースは罰金に作成されていると私はダミーデータを追加することができますし、私はCOLUMN_PICTURE列にサンプル描画可能を追加しました。私はこのラインを明確にするため

int imgColumnIndex = cursor.getColumnIndex(ToolEntry.COLUMN_PICTURE); 

を使用する場合でも、bindView方法

int typeColumnIndex = cursor.getColumnIndex(ToolEntry.COLUMN_TOOL_TYPE); 
int costColumnIndex = cursor.getColumnIndex(ToolEntry.COLUMN_COST); 
int stockLevelColumnIndex = cursor.getColumnIndex(ToolEntry.COLUMN_STOCK_LEVEL); 
int indicatorStock = cursor.getColumnIndex(ToolEntry.COLUMN_IN_STOCK); 
int imgColumnIndex = cursor.getColumnIndex(ToolEntry.COLUMN_PICTURE); 

他のすべてのcolumnIndexが仕事を取得しますから来ています。私は他の人の後にピクチャ列を追加しました。しかし、私はキャッシュ/アプリケーションのデータを格納し、それをアンインストールしました。

常に-1を返します。カーソルは、他の列の正しい値を戻すので機能しています。以下はダミーデータを持つSQLiteデータベースのダンプです。私はその後、ゼロで2番目の行のBLOBエントリを書きました。だから私はコンテンツの値を使用することができます values.put(ToolEntry.COLUMN_PICTURE、0);

Image of Database

しかし、私は
toolImg = cursor.getBlob(imgColumnIndex)を使用してみてください。

インデックスがこれは私の一部に愚かな間違いであることが判明した時に-1

+0

これはDropbox [link](https://photos-6.dropbox.com/t/2/AAAdKzP9kbF_QLjsQJh2SbHgDbK375I3MLc5_jzVNfZVeg/12/1129520/png/32x32/3/1496955600/0/2/)の画像へのリンクです。 tools.png/EM7Tfhi6ycLHASAHKAc/gLQcLzeqzPrRgeTrF31kMXVIxfQUxi8DwgwHxMHyqNo?dl = 0&size = 2048x1536&size_mode = 3) –

+0

どこからカーソルを取得しますか? –

+0

これはbindViewメソッドから取得されます。int typeColumnIndex = cursor.getColumnIndex(ToolEntry.COLUMN_TOOL_TYPE); int costColumnIndex = cursor.getColumnIndex(ToolEntry.COLUMN_COST); intStockLevelColumnIndex = cursor.getColumnIndex(ToolEntry.COLUMN_STOCK_LEVEL); int indicatorStock = cursor.getColumnIndex(ToolEntry.COLUMN_IN_STOCK); int imgColumnIndex = cursor.getColumnIndex(ToolEntry.COLUMN_PICTURE);他のすべての行がColumnIndexを正常に動作させています。 - David Crowley 1分前に編集 –

答えて

0

であるように、それはクラッシュします。私は1つの場所で正しく投影を定義しましたが、別の投影定義で新しい列を省略しました。