2017-06-08 33 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數據庫轉儲。然後,我用零寫了第二行的BLOB條目。所以我可以使用內容值 values.put(ToolEntry.COLUMN_PICTURE,0);

Image of Database

但是當我嘗試使用
toolImg = cursor.getBlob(imgColumnIndex);

它崩潰的指數爲-1

+0

這是鏈接到Dropbox上的圖像[鏈接](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); int stockLevelColumnIndex = 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

事實證明,這是我的一個愚蠢的錯誤。我在一個地方正確定義了我的投影,但在另一個投影定義中遺漏了新列。