2016-11-07 59 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(); 
       } 
      });