我是Android新手。
我想基于CheckBox值更新表数据。
但是它没有更新表-相反,我收到了No Such Table error。
这是代码:
public class CheckListActivity extends Activity {
CheckBox chkTask1, chkTask2, chkTask3, chkTask4, chkTask5, chkTask6,
chkTask7, chkTask8, chkTask9, chkTask10;
Button btnSave;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_check_list);
chkTask1 = (CheckBox) findViewById(R.id.task1_option);
chkTask2 = (CheckBox) findViewById(R.id.task2_option);
chkTask3 = (CheckBox) findViewById(R.id.task3_option);
chkTask4 = (CheckBox) findViewById(R.id.task4_option);
chkTask5 = (CheckBox) findViewById(R.id.task5_option);
chkTask6 = (CheckBox) findViewById(R.id.task6_option);
chkTask7 = (CheckBox) findViewById(R.id.task7_option);
chkTask8 = (CheckBox) findViewById(R.id.task8_option);
chkTask9 = (CheckBox) findViewById(R.id.task9_option);
chkTask10 = (CheckBox) findViewById(R.id.task10_option);
btnSave = (Button) findViewById(R.id.button2);
btnSave.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String error = "";
if (chkTask1.isChecked()) {
error = updateCheckList(1, 1);
} else {
error = updateCheckList(0, 1);
}
if (chkTask2.isChecked()) {
error = updateCheckList(1, 2);
} else {
error = updateCheckList(0, 2);
}
if (chkTask3.isChecked()) {
error = updateCheckList(1, 3);
} else {
error = updateCheckList(0, 3);
}
if(error.length()>0){
Toast.makeText(CheckListActivity.this, "ERROR " +error,
Toast.LENGTH_LONG).show();
}else{
Toast.makeText(CheckListActivity.this, "Successfully Saved...!",Toast.LENGTH_LONG).show();
}
}
});
}
private String updateCheckList(int flag, int id) {
String errorStr = "";
SQLiteDatabase db;
db = openOrCreateDatabase("CheckList.db",
SQLiteDatabase.CREATE_IF_NECESSARY, null);
try {
String sql = "UPDATE CheckList SET CHECKEDFLAG = " + flag
+ " WHERE ID = " + id;
db.execSQL(sql);
} catch (Exception e) {
errorStr = errorStr + e.getMessage();
}
return errorStr;
}
}
大胆的猜测:您是在应用首次运行后添加表格的。
解决方案:您必须卸载并重新安装您的应用程序。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句