我試圖創建一個包含4列(包括_id)的表,並且無論我做什麼,它都會一直創建只有3列(包括_id)的表。使用錯誤的列號創建數據庫
我的表定義如下:
private static final String DATABASE_CREATE =
"create table collections (_id integer primary key autoincrement, "
+ "name text not null, description text not null, image integer not null);";
而且我的onCreate:
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(DATABASE_CREATE);
}
我如何訪問數據:
public View getView(int position, View convertView, ViewGroup parent) {
cursor.moveToPosition(position);
LinearLayout ll = new LinearLayout(mContext);
ll.setOrientation(LinearLayout.VERTICAL);
ImageView i = new ImageView(mContext);
i.setImageResource(cursor.getInt(3)); //access to the image column
i.setScaleType(ImageView.ScaleType.FIT_XY);
i.setLayoutParams(new Gallery.LayoutParams(150, 150));
// The preferred Gallery item background
i.setBackgroundResource(mGalleryItemBackground);
ll.addView(i);
TextView tv = new TextView(ll.getContext());
tv.setTag(mText[position]);
tv.setText(cursor.getString(1)); //access to the name column
tv.setLayoutParams(new Gallery.LayoutParams(48, 48));
ll.addView(tv);
return ll;
}
無論我怎麼努力,它不斷將列圖像從表格中移出...我將很感激我獲得的任何幫助。
你有沒有嘗試命名列'_image'? – 2011-12-29 03:34:12
嗯,我自己也有同樣的問題,請參閱http://stackoverflow.com/questions/8656146/column-not-created-in-sqlite3-table。如果你發現原因,請告訴我。我重寫了我的代碼和列名無數次,似乎沒有任何工作。它就像一個幽靈專欄。 – 2011-12-29 03:37:52
將圖像列名更改爲其他內容並嘗試。 – kosa 2011-12-29 03:42:36