It gives the above error due to the Context that I provided to the alertdialog builder.
Give:
new AlertDialog.Builder (getParent ()). setMessage ("Hello world"). show ();
We just need to call getParent () instead of AlertDialog.Builder (this)
source share