警报对话框未显示

时间:2011-10-26 14:01:15

标签: android dialog alert

大家好我只是通过点击一个按钮在android中创建一个警告对话框。我使用了XML的onClick属性并调用了函数。我的代码是

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();}

但是这段代码没有显示警告并给出错误,如

BadTokenException: Unable to add window -- token null is not for an application. 

请告诉我这段代码有什么问题。

1 个答案:

答案 0 :(得分:21)

new AlertDialog.Builder(getApplicationContext());

我认为这是问题所在。你试过了吗?

new AlertDialog.Builder(YourActivityClassName.this);
相关问题