Question: I am a beginner android developer. 
I have a database table that counts the following columns: \_id, fistName, lastName and username what is set to unique.

When I add another person in my table and the username already exist I create an AlertDialog, but this AlertDialog does not appear.

This is my source code:

```
try {
        personRepository.AddPerson(persons);
    } catch (SQLiteConstraintException ex) {
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                context);
        alertDialogBuilder.setTitle("User already exist!");
        alertDialogBuilder.setMessage("Choose another username!")
                .setPositiveButton("Yes",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                    int id) {
                                dialog.cancel();
                            }
                        });
        AlertDialog alertDialog = alertDialogBuilder.create();
        alertDialog.show();
    }

```

Can someone help me?

Answer: 
try this

```
AlertDialog alert;
alert=new AlertDialog.Builder(YourActivity.this)
                .setCancelable(false)
                .setMessage("Message")
                .setPositiveButton("Okay", new DialogInterface.OnClickListener()
                {

                    @Override
                    public void onClick(DialogInterface dialog, int which)
                    {
                        // TODO Auto-generated method stub
                        dialog.dismiss();
                    }
                }).show();

```
If your `AddPerson` method call `insertOrThrow` then change 

```
catch (SQLiteConstraintException ex)   

```

to 

```
catch (SQLException ex)

```