Good day. It is impossible to update the record in the database table. By clicking, an AlertDialog is output, into which we enter a new value, which must then be updated in the database. I tried to do it this way, but I get:
E / Surface: getSlotFromBufferLocked: unknown buffer: 0x7f7cd3bfa0

public void editTask(View view){ final EditText taskEdit = new EditText(this); AlertDialog dialog = new AlertDialog.Builder(this).setTitle("Редактирование заметки").setMessage("Введите новый текст заметки ") .setView(taskEdit).setPositiveButton(" Изменить ", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String task = String.valueOf(taskEdit.getText()); SQLiteDatabase db = mHelper.getWritableDatabase(); ContentValues newvalues = new ContentValues(); newvalues.put(com.example.alexandrkuchinsky.myapplication.db.task.TaskEntry.COL_TASK_TITLE,task); String where = TaskEntry._ID + " = ?"; db.update(TaskEntry.TABLE, newvalues, where, null); db.close(); updateUI(); } }) .setNegativeButton(" Отмена ", null).create(); dialog.show(); } 

class TaskHelper

  public class TaskHelper extends SQLiteOpenHelper { public TaskHelper(Context context){ super(context, task.DB_name, null, task.Db_versiom); } @Override public void onCreate(SQLiteDatabase db) { String createTable = "CREATE TABLE " + task.TaskEntry.TABLE + " ( " + task.TaskEntry._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + task.TaskEntry.COL_TASK_TITLE + " TEXT NOT NULL);"; db.execSQL(createTable); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL("DROP TABLE IF EXISTS " + task.TaskEntry.TABLE); onCreate(db); } } 

Class task

 public class task { public static final String DB_name = "cas.example.com.todolist.db"; public static final int Db_versiom = 1; public class TaskEntry implements BaseColumns{ public static final String TABLE = "tasks"; public static final String COL_TASK_TITLE = "title"; } } 

updateUI method

  private void updateUI(){ ArrayList<String> tasklist = new ArrayList<>(); SQLiteDatabase db = mHelper.getReadableDatabase(); Cursor cursor = db.query(TaskEntry.TABLE, new String[]{TaskEntry._ID, TaskEntry.COL_TASK_TITLE}, null, null, null, null, null); while (cursor.moveToNext()) { int index = cursor.getColumnIndex(TaskEntry.COL_TASK_TITLE); tasklist.add(cursor.getString(index)); } if (mAdapter == null) { mAdapter = new ArrayAdapter<>(this, R.layout.item_todo, R.id.task_title, tasklist); mTaskListView.setAdapter(mAdapter); } else{ mAdapter.clear(); mAdapter.addAll(tasklist); mAdapter.notifyDataSetChanged(); } 

Be kind: tell me what I was wrong?

  • What is the updateUI() (code) method and on which line is the error? - pavlofff
  • updateUI () attached, does not issue an error. When clicked, it outputs: E / Surface: getSlotFromBufferLocked: unknown buffer: 0x7f7cd3bfa0 - studer
  • Looks like you got this error here .. issuetracker.google.com/issues/37069061 - ZigZag

0