I'm calling a method, when I click the button and this error appears, but I do not know what it means:
java.lang.IllegalStateException: Could not find method (View) in a parent or ancestor Context for android: onClick attribute defined on view class android.support.v7.widget.AppCompatButton with id 'btnAgendar'
Follow my code
public class AgendamentoActivity extends AppCompatActivity {
private ProfissionalPojo p;
private ListView listAgendamentos;
private Spinner spinnerHorario;
private String dadoHora;
private StringCharacterIterator editText;
private Calendar myCalendar;
private String diaAgenda;
private int idusuario;
private String nome;
private String sobrenome;
private String dia;
private String hora;
private Button botaoAgenda;
//private horario adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_agendamento);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Bundle extra = getIntent().getExtras();
if(extra != null){
idusuario = extra.getInt("idusuario");
nome = extra.getString("nome");
sobrenome = extra.getString("sobrenome");
}
Toast.makeText(this, "id usuario "+idusuario, Toast.LENGTH_SHORT).show();
final Calendar myCalendar = Calendar.getInstance();
p = (ProfissionalPojo) getIntent().getSerializableExtra("pro");
agendar(p.getIdprofissional(), idusuario, nome, sobrenome, dia, hora);
listAgendamentos = ((ListView)findViewById(R.id.lvAgendamentos));
botaoAgenda = ((Button) findViewById(R.id.btnAgendar));
EditText editText = ((EditText)findViewById(R.id.edtDia));
spinnerHorario = (Spinner) findViewById(R.id.spHorario);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.spHorario, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerHorario.setAdapter(adapter);
spinnerHorario.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener(){
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
if(i == 0){
//Toast.makeText(getBaseContext(), "8:00 - 9:00", Toast.LENGTH_LONG).show();
String dadoHora = "8:00 - 9:00";
}else if (i == 1){
//Toast.makeText(getBaseContext(), "9:00 - 10:00", Toast.LENGTH_LONG).show();
String dadoHora = "9:00 - 10:00";
}else if (i == 2){
//Toast.makeText(getBaseContext(), "10:00 - 11:00", Toast.LENGTH_LONG).show();
String dadoHora = "10:00 - 11:00";
}else if (i == 3){
//Toast.makeText(getBaseContext(), "11:00 - 12:00", Toast.LENGTH_LONG).show();
String dadoHora = "11:00 - 12:00";
}else if (i == 4){
//Toast.makeText(getBaseContext(), "12:00 - 13:00", Toast.LENGTH_LONG).show();
String dadoHora = "12:00 - 13:00";
}else if (i == 5){
//Toast.makeText(getBaseContext(), "13:00 - 14:00", Toast.LENGTH_LONG).show();
String dadoHora = "13:00 - 14:00";
}else if (i == 6){
//Toast.makeText(getBaseContext(), "14:00 - 15:00", Toast.LENGTH_LONG).show();
String dadoHora = "14:00 - 15:00";
}else if (i == 7){
//Toast.makeText(getBaseContext(), "15:00 - 16:00", Toast.LENGTH_LONG).show();
String dadoHora = "15:00 - 16:00";
}else if (i == 8){
//Toast.makeText(getBaseContext(), "16:00 - 17:00", Toast.LENGTH_LONG).show();
String dadoHora = "16:00 - 17:00";
}else if (i == 9){
//Toast.makeText(getBaseContext(), "17:00 - 18:00", Toast.LENGTH_LONG).show();
String dadoHora = "17:00 - 18:00";
}
dadoHora = spinnerHorario.getSelectedItem().toString();
exibeHora();
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
final DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
// TODO Auto-generated method stub
myCalendar.set(Calendar.YEAR, year);
myCalendar.set(Calendar.MONTH, monthOfYear);
myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
updateLabel(myCalendar);
}
};
editText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
new DatePickerDialog(AgendamentoActivity.this, date, myCalendar
.get(Calendar.YEAR), myCalendar.get(Calendar.MONTH),
myCalendar.get(Calendar.DAY_OF_MONTH)).show();
}
});
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String time = sdf.format(myCalendar.getTime());
}
public void exibeDia(){
final TextView tvDia = ((TextView) findViewById(R.id.tvDia));
tvDia.setText(diaAgenda);
dia = tvDia.toString();
}
public void exibeHora(){
final TextView tvHora = ((TextView) findViewById(R.id.tvHora));
tvHora.setText(dadoHora);
hora = tvHora.toString();
}
private void updateLabel(Calendar myCalendar) {
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
diaAgenda = sdf.format(myCalendar.getTime());
exibeDia();
}
public void agendar(final String idprofissional, int idusuario, String nome, String sobrenome, String dia, String hora) {
Log.d("TAG", "idpro " + idprofissional + " idusuario " + idusuario + " nome " +nome+ " sobrenome " +sobrenome+ " dia " + dia + " hora " + hora);
}
}