android – AlertDialog按钮不存在

android – AlertDialog按钮不存在,第1张

概述突然(这个项目代码没有任何变化)我开始得到一个错误: java.lang.RuntimeException: Unable to start activity ComponentInfo{<package>}: java.lang.IllegalArgumentException: Button does not exist 该错误指向尚未调用的方法. private void dialog(St 突然(这个项目代码没有任何变化)我开始得到一个错误:

java.lang.RuntimeException: Unable to start activity ComponentInfo{<package>}: java.lang.IllegalArgumentException: button does not exist

该错误指向尚未调用的方法.

private voID dialog(String Title,String content){    AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();    alertDialog.setTitle(Title);    alertDialog.setMessage(content);    alertDialog.setCancelable(true);    alertDialog.setbutton(1,"OK",new DialogInterface.OnClickListener() {           public voID onClick(DialogInterface dialog,int which) {               dialog.dismiss();               }            });    alertDialog.show();}

我试图在其他项目中复制并使用该代码 – 结果相同,并且它不久前工作(相同的目标API等).知道我在忽视什么吗?

解决方法 不要在 setButton(...)中硬编码1.使用 DialogInterface类中的常量指定哪个按钮

DialogInterface.BUTTON_NEGATIVE

DialogInterface.BUTTON_POSITIVE

DialogInterface.BUTTON_NEUTRAL

总结

以上是内存溢出为你收集整理的android – AlertDialog按钮不存在全部内容,希望文章能够帮你解决android – AlertDialog按钮不存在所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1123466.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存