• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Unable to obtain bluetooth adapter

 
Ranch Hand
Posts: 65
Android Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

By the way, BluetoothAdapter class is used to check if bluetooth is supported in the device.
reply
    Bookmark Topic Watch Topic
  • New Topic