gpt4 book ai didi

android - 单击按钮以显示警报对话框时应用程序崩溃

转载 作者:行者123 更新时间:2023-11-29 02:27:40 24 4
gpt4 key购买 nike

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

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 failed!

在我无法理解的 logcat 中,因为我是编码新手,附上 .Java 和 Logcat 屏幕截图。这是 Logcat:

enter image description here

这是 .java 类:

enter image description here

最佳答案

好的,我认为您需要提供 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();

关于android - 单击按钮以显示警报对话框时应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51319436/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com