Having trouble dismissing dialog in Android [AlertDialog]

view story

http://stackoverflow.com – final String[] choices = { "Item 1", "Item 2", "Item 3"}; final AlertDialog dialog= new AlertDialog.Builder( TestSubjectCalendar.this) .setTitle("Title") .setSingleChoiceItems(choices, pos, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); //gives error // MORE CODE } }).create(); dialog.show(); dialog.dismiss() is giving the following errors: The local variable dialog may not have been initialized What I want is that when I click an item from (HowTos)