Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Android and the fly likes Unable to obtain bluetooth adapter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Android
Bookmark "Unable to obtain bluetooth adapter" Watch "Unable to obtain bluetooth adapter" New topic

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

What could be the reason?

Thanks in advance!

Peter Johnson

Joined: May 14, 2008
Posts: 5778

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.
I agree. Here's the link:
subject: Unable to obtain bluetooth adapter
Similar Threads
how to view a web camera via URL
Can't make SocketServer in the emulator
how to transfer images to ftp server in android
How to pass POJOs / data / values between activities?
My Custom Intents do not work