Hi all I am creating an alert dialog in android by clicking a button. I used onClick property of XML and calling function. My code is
public void selectPhoneType(View view)
{
String [] item = {"Home", "Work", "Mobile", "Work Fax", "Home Fax", "Pager", "Other", "Custom"};
AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
builder.setTitle("Select Label");
AlertDialog alert = builder.create();
alert.show();}
but this code is not showing alert and giving error like
BadTokenException: Unable to add window -- token null is not for an application.
Please tell me what is wrong with this code.
new AlertDialog.Builder(getApplicationContext());
I think this is the problem. Have you tried:
new AlertDialog.Builder(YourActivityClassName.this);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With