繁体   English   中英

单击按钮显示警报对话框时,应用崩溃

[英]App crashing when clicking on the button to show Alert Dialog

我在按钮的onclick后面创建了一个警告对话框,但是当我单击该按钮时,它使应用程序崩溃,引发以下异常。

java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity 

07-13 11:51:12.445 21054-21054 / com.vshine.neuron.riseshine E / MultiWindowProxy:getServiceInstance失败!

在我不懂编码的logcat中,.Java和Logcat屏幕快照已附加。 这是Logcat:

在此处输入图片说明

这是.java类:

在此处输入图片说明

只是尝试将Activity而不是AppCompatActivity继承到您的quiz.java活动中

就像代码顶部

public class Quiz extends Activity{

有关更多信息,请查看此帖子。

好的,我认为您需要提供活动的上下文。 尝试这个:

new AlertDialog.Builder(YourClassName.this)
                .setTitle("Title")
                .setMessage("Message?")
                .setCancelable(false)
                .setNegativeButton("No", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        //Function on no
                })
                .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                       //Function on yes
                    }
                })
                .show();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM