android - Error Calling Intent -


there error when call intent startactivity (new intent (this, advogado1.class)), how should proceed call intent

            alertdialog.builder alert = new alertdialog.builder(this);              alert.settitle("atenção");             alert.setmessage("digite o numero da oab");              // set edittext view user input             final edittext input = new edittext(this);             alert.setview(input);              alert.setpositivebutton("ok",                     new dialoginterface.onclicklistener() {                         public void onclick(dialoginterface dialog,                                 int whichbutton) {                              int oab = integer.parseint(input.gettext()                                     .tostring());                             // value!                              if (oab == 1) {                                  startactivity(new intent(this, advogado1.class));                             }                          }                     });              alert.setnegativebutton("cancelar",                     new dialoginterface.onclicklistener() {                         public void onclick(dialoginterface dialog,                                 int whichbutton) {                             // canceled.                         }                     });              alert.show(); 

the call to,

startactivity(new intent(this, advogado1.class)); 

should not use 'this', should use,

startactivity(new intent(nameofyouractivity.this, advogado1.class));  

because this refers anonymous class extending dialoginterface.onclicklistener, , not activity class. intent needs caller class instance of activity.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -