[英]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.