我是一名学生,是 Android 和 Sqlite 数据库的新手。
我一直在尝试更新我的 sqLite 数据库中的数据,我尝试了很多方法来更新数据,经过大量研究,它在 Update 类中出现了一个错误,即 id。错误:(92, 35) 错误: 找不到符号变量 id 错误信息
请检查我的代码,让我知道我的错误在哪里。谢谢你。
数据库助手类:
public boolean updateData(long id, String new_question, String new_ans1, String new_ans2, String new_ans3, String new_ans4, SQLiteDatabase sqLiteDatabase )
{
ContentValues contentValues = new ContentValues();
contentValues.put(AdminContact.Question.COLUMN_QUESTION, new_question);
contentValues.put(AdminContact.Question.COLUMN_ANSWER1, new_ans1);
contentValues.put(AdminContact.Question.COLUMN_ANSWER2, new_ans2);
contentValues.put(AdminContact.Question.COLUMN_ANSWER3, new_ans3);
contentValues.put(AdminContact.Question.COLUMN_ANSWER4, new_ans4);
// String selection = AdminContact.Question.TABLE_QUIZ + " LIKE ?";
//String[] selection_arg = {new_question};
sqLiteDatabase.update(AdminContact.Question.TABLE_QUIZ, contentValues, AdminContact.Question.ID + "=" + id, null);
return i > 0;
}
This is my Create Table:
private static final String CREATE_QUERY = "CREATE TABLE "+ AdminContact.Question.TABLE_QUIZ+"("+ AdminContact.Question.ID+" INTEGER PRIMARY KEY NOT NULL,"+ AdminContact.Question.COLUMN_QUESTION+" TEXT NOT NULL,"+
AdminContact.Question.COLUMN_ANSWER1+" TEXT NOT NULL,"+ AdminContact.Question.COLUMN_ANSWER2+" TEXT NOT NULL,"+ AdminContact.Question.COLUMN_ANSWER3+" TEXT NOT NULL,"+ AdminContact.Question.COLUMN_ANSWER4+" TEXT NOT NULL);";
And my Update class:
public void updateData(View view)
{
helper = new DatabaseHelper(this);
sqLiteDatabase = helper.getWritableDatabase();
String question, ans1, ans2, ans3, ans4;
question = New_Question.getText().toString();
ans1 = New_Ans1.getText().toString();
ans2 = New_Ans2.getText().toString();
ans3 = New_Ans3.getText().toString();
ans4 = New_Ans4.getText().toString();
helper.updateData(id,question,ans1,ans2,ans3,ans4,sqLiteDatabase);
Toast.makeText(getApplicationContext()," Successfully Updated", Toast.LENGTH_LONG).show();
finish();
}