我想用默認值創建一行表格,然後它會更新。使用默認值創建表格
我無法顯示圖像,這是因爲: 「你至少需要10聲譽發表圖片」,我很抱歉:
來自:
到:
public class DataBaseHelper extends SQLiteOpenHelper {
.
.
.
private static final String CREATE_TABLE_SETTING = "CREATE TABLE " +
MYSETTING + "(" + ID_SETTING + " INTEGER 0," +
PIC_SETTING + " INTEGER DEFAULT 1," + WITH_PIC_SETTING + " INTEGER DEFAULT 7," +
WITHOUT_PIC_SETTING + " INTEGER DEFAULT 10" + ")";
//my update function
public void updateSetting(int key,int pic , int number_with_pic , int number_without_pic){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(ID_SETTING, key);
values.put(PIC_SETTING, pic);
values.put(WITH_PIC_SETTING, number_with_pic);
values.put(WITHOUT_PIC_SETTING, number_without_pic);
db.update(MYSETTING, values, ID_SETTING + " = ? ", new String[] {String.valueOf(key)});
}
個
public class Settings extends Fragment {
DataBaseHelper db ;
ArrayList<Integer> arraysetting ;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view=inflater.inflate(R.layout.frag_2,container,false);
db = new DataBaseHelper(getActivity());
db.updateSetting(0, 4, 3, 2);
//arraysetting = new ArrayList<Integer>();
//arraysetting.addAll(db.getAllSetting());
return view;
}
}
我的錯誤:
01-23 01:32:51.201: E/AndroidRuntime(632): FATAL EXCEPTION: main
01-23 01:32:51.201: E/AndroidRuntime(632): android.database.sqlite.SQLiteException: no such table: mysetting: , while compiling: UPDATE mysetting SET pic_setting=?,without_setting=?,with_setting=?,id_setting=? WHERE id_setting = ?
01-23 01:32:51.201: E/AndroidRuntime(632): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
您的'DataBaseHelper'重寫'onCreate(SQLiteDatabase)'嗎? –
yes,db.execSQL(CREATE_TABLE_SETTING); – user3103823
您的logcat是否顯示與創建數據庫相關的任何錯誤?您發佈的錯誤表明該表不存在,表示創建時存在問題。 –