Olá,
Ao executar o app após implementar o código abaixo:
Activity
@Override
public void onCreateContextMenu(ContextMenu menu, View v, final ContextMenu.ContextMenuInfo menuInfo) {
MenuItem deletar = menu.add("Deletar");
deletar.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
Aluno aluno = (Aluno) listaAlunos.getItemAtPosition(info.position);
AlunoDao dao = new AlunoDao(ListaAlunosActivity.this);
dao.deleta(aluno);
dao.close();
return false;
}
});
}
DAO
public void deleta(Aluno aluno) {
SQLiteDatabase db = getWritableDatabase();
String[] params = {aluno.getId().toString()};
db.delete("Alunos", "id = ?", params);
}
Ocorre a exceção abaixo, o app para e fecha:
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: br.com.agenda, PID: 23330
java.lang.NoSuchMethodError: No virtual method deleta(Lbr/com/agenda/model/Aluno;)V in class Lbr/com/agenda/dao/AlunoDAO; or its super classes (declaration of 'br.com.agenda.dao.AlunoDAO' appears in /data/data/br.com.agenda/files/instant-run/dex/slice-slice_3-classes.dex)
at br.com.agenda.ListaAlunosActivity$2.onMenuItemClick(ListaAlunosActivity.java:61)
at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:148)
at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:904)
at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:894)
at com.android.internal.view.menu.MenuPopup.onItemClick(MenuPopup.java:128)
at android.widget.AdapterView.performItemClick(AdapterView.java:310)
at android.widget.AbsListView.performItemClick(AbsListView.java:1156)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3121)
at android.widget.AbsListView$3.run(AbsListView.java:4036)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Disconnected from the target VM, address: 'localhost:8799', transport: 'socket'
O mesmo problema acontece quando eu altero o nome do método listarAlunos() para listar(), por exemplo.