如何重新解决?错误:(51,23)错误:没有为setButton方法找到合适的方法

时间:2016-11-07 07:26:05

标签: android android-layout android-studio

花了1天的时间在解决方案中我终于在这里发布了没有解决方案为我解决: 如何解决此错误请帮我解决这个问题

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();
        }

先谢谢

1 个答案:

答案 0 :(得分: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();
               }
           });