This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills: The software developer's life manual and have John Sonmez on-line!
See this thread for details.
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unable to obtain bluetooth adapter

 
Renjith Mohan
Ranch Hand
Posts: 65
Android Chrome Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Renjith Mohan
Ranch Hand
Posts: 65
Android Chrome Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65
Android Chrome Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

By the way, BluetoothAdapter class is used to check if bluetooth is supported in the device.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic