gpt4 book ai didi

在android中创建警报对话框时出现java.lang.IllegalStateException

转载 作者:行者123 更新时间:2023-12-02 03:09:25 29 4
gpt4 key购买 nike

这里是初学者..

我无法创建警报对话框。当我使用 `alertDialog.show();

时会发生这种情况

这个错误--

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

我的代码,

 logoImage.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {

AlertDialog.Builder builder=new AlertDialog.Builder(getApplicationContext());
builder.setTitle("hello");
builder.setMessage("hello how are you");
AlertDialog alertDialog= builder.create();
alertDialog.show(); //line


}

});

我的日志猫..

 java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:555)
at android.support.v7.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:518)
at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:466)
at android.support.v7.app.AppCompatDialog.setContentView(AppCompatDialog.java:94)
at android.support.v7.app.AlertController.installContent(AlertController.java:232)
at android.support.v7.app.AlertDialog.onCreate(AlertDialog.java:279)
at android.app.Dialog.dispatchOnCreate(Dialog.java:394)
at android.app.Dialog.show(Dialog.java:283)
at com.abmm.include_activity$15.onClick(include_activity.java:459)

谢谢各位 friend ..

最佳答案

改变,

AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());

AlertDialog.Builder builder = new AlertDialog.Builder(this);

关于在android中创建警报对话框时出现java.lang.IllegalStateException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57003795/

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