I created a alert dialog behind the onclick of a button but when i click that button it crashes the app throw the following exception.
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!
in logcat that I couldn't able to understand as I'm new to coding, .Java and Logcat screenshots are attached. This is Logcat :
This is .java class :
just try to inherit Activity
instead of AppCompatActivity
to your quiz.java
activity
like at top of code
public class Quiz extends Activity{
for more check this post.
Ok i think you need to provide context of the Activity. Try this:
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();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.