2016-11-07 73 views
-1

花费1天的解决方案后,我终于在这里发布它没有解决方案为我制定: 如何解决此错误,请帮助我这个如何resoleve?错误:(51,23)错误:找不到合适的方法找到setButton方法

Error:(51, 23) error: no suitable method found for setButton(String,<anonymous OnClickListener>) 
method AlertDialog.setButton(int,CharSequence,Message) is not applicable 
(actual and formal argument lists differ in length) 
method AlertDialog.setButton(int,CharSequence,OnClickListener) is not applicable 
(actual and formal argument lists differ in length) 

而且我的代码是:=

alertDialog = new AlertDialog.Builder(MainActivity.this).create(); 

      alertDialog.setTitle("Error"); 
      alertDialog.setMessage("Internet not available, Cross check your internet connectivity and try again"); 
      alertDialog.setButton("OK",new DialogInterface.OnClickListener(){ 
       public void onClick(DialogInterface dialogInterface,int which){ 
        finish(); 
       } 
      }); 

      alertDialog.show(); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 

在先进的感谢

+3

变化'setButton'到'setPositiveButton' –

+0

改变了它,但不制定先生。 – Champandorid

回答

1

这里是解决方案:= 变化哟我们的代码:

alertDialog = new AlertDialog.Builder(MainActivity.this).create(); 

      alertDialog.setTitle("Error"); 
      alertDialog.setMessage("Internet not available, Cross check your internet connectivity and try again"); 
      alertDialog.setButton(Dialog.BUTTON_POSITIVE,"OK",new DialogInterface.OnClickListener(){ 
       public void onClick(DialogInterface dialogInterface,int which){ 
        finish(); 
       } 
      });