Are you running this code on your phone or on the adapter? I don't think that the adapter has bluetooth.
Also, you code could use some rearranging - you check adapter for null twice while you you could check just once, and
you should not use adapter (lines 20-22) unless it is non-null