Author
Unable to obtain bluetooth adapter
Renjith Mohan
Ranch Hand
Joined: Nov 28, 2008
Posts: 65
Hi all,
I am writing a small bluetooth application to search for devices. However, the bluetooth adapter instance is always null. See the code below.
And the manifest file is
Message in the LogCat is null pointer exception at line 20 (refer BluetoothDemo.java)
What could be the reason?
Thanks in advance!
--Renjith
Peter Johnson
author
Bartender
Joined: May 14, 2008
Posts: 5536
posted Jun 15, 2011 08:44:55
0
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
JBoss In Action
Renjith Mohan
Ranch Hand
Joined: Nov 28, 2008
Posts: 65
I tried running it on an emulator as well on the phone. Every time I try on the phone, it ends up with the message
The application has stopped unexpectedly. Please try later.
Yeah, i wrote it twice. it was a typo...the actual source has only one check.
Renjith Mohan
Ranch Hand
Joined: Nov 28, 2008
Posts: 65
By the way, BluetoothAdapter class is used to check if bluetooth is supported in the device.
subject: Unable to obtain bluetooth adapter