I have created a custom dialog and a layout xml:
A dialog is always created and displayed as part of an Activity. According to Android References:
If you decide to create a dialog outside of the onCreateDialog() method, it will not be attached to an Activity. You can, however, attach it to an Activity with setOwnerActivity(Activity).
Also, are you passing the object returned by getApplicationContext(); to the constructor of TestDialog?