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

时间:2018-07-13 07:04:11

标签: android api android-linearlayout

我在按钮的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:

enter image description here

这是.java类:

enter image description here

2 个答案:

答案 0 :(得分:0)

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

像在代码顶部

public class Quiz extends Activity{

更多支票this post.

答案 1 :(得分:0)

好吧,我认为您需要提供活动的背景信息。 试试这个:

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();
相关问题